gpt4 book ai didi

javascript - Rails生产模式下如何压缩/public中的js,css文件

转载 作者:太空宇宙 更新时间:2023-11-03 18:08:02 24 4
gpt4 key购买 nike

我在我的 Rails 元素中放入了一堆 javascript 插件和图像、css。

这是结构。

公共(public)/CSS公共(public)/js公共(public)/图片

我加了

config.assets.compile = true  
config.serve_static_assets = true

在生产中.rb

如果文件在/app/assets/中,它可以很好地压缩

外部插件呢?

我需要做什么才能压缩/public 中的所有库?

最佳答案

Assets 管道

你错过了 asset pipeline 的重点;特别是 precompilation过程:

Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline.

Compiled assets are written to the location specified in config.assets.prefix. By default, this is the /assets directory.

You can call this task on the server during deployment to create compiled versions of your assets directly on the server. See the next section for information on compiling locally.

--

预编译

你的问题可以通过precompile your asset来回答 - 为此,你需要能够将你的相关 Assets 文件存储在app/assets/....

您可以使用以下命令在生产环境中预编译 Assets :

$ rake assets:precompile RAILS_ENV=production

这基本上会将您的各种 Assets 文件压缩/缩小到您分配给预编译过程的不同文件中。默认情况下,它们都被放入 application.*(application.css/application.js 等)

--

修复

为此,您需要将所有文件移动到 app/assets/... 文件夹中。这会将它们放入 Assets 管道,这将允许 Rails 正确地预编译 Assets ,并根据需要将它们发送到 /public 文件夹

关于javascript - Rails生产模式下如何压缩/public中的js,css文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24323149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com