Rails 3.1 自定义 sprockets 预编译资源

发布于 2024-12-05 16:35:00 字数 387 浏览 1 评论 0原文

我正在尝试自定义预编译哪些资产。在生产中,我只希望编译 application.js 和 applicaiton.css,而不是包含所有后续文件。

例如给出以下文件,当我运行预编译rake任务时,我只想输出一个文件(appliation.css)

##application.css
//include components/form.elements
//include components/lists

默认是预编译assets目录中的所有资源,这很混乱。

编辑更正默认预编译assets目录中的所有非js和css文件。但是,如果您有一个像 form.elements.js 这样的文件,sprockets 会预编译它,认为它是一个非 js/css 文件。

I am trying to customize what assets get precompiled. In production I only want application.js and applicaiton.css to be compiled and not all the subsequent files that are included.

For example giving the following files I only want one file (appliation.css) to be output when I run the precompile rake task

##application.css
//include components/form.elements
//include components/lists

The default is to precompile all assets in the assets directory and it is quite messy.

EDIT correction it is the default to precompile all non js and css files in the assets directory. If however you have a file like form.elements.js sprockets will precompile it thinking it is a non js/css file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-12-12 16:35:00

查看 sprockets 文档,它非常广泛且写得很好。

对于您的特定问题,以下 application.css 将仅递归地包含 components/form_elementscomponents/lists 目录:

/*
 *= require_tree components/form_elements
 *= require_tree components/lists
*/

如果 form_elementslists是css文件,只需将require_tree替换为require即可。

Check the sprockets documentation, it is quite extensive and well-written.

For your particular problem, the following application.css would only include the components/form_elements and components/lists directories, recursively:

/*
 *= require_tree components/form_elements
 *= require_tree components/lists
*/

If form_elements and lists are css files, just replace require_tree with require.

绿萝 2024-12-12 16:35:00

只要您没有任何包含额外句点的文件,默认的预编译选项就会起作用。像(jquery.treeview.js)一样,

我能够通过显式定义我想要编译的各个文件来让我的资产按照我想要的方式进行编译。

 config.assets.precompile = [ 'application.css' ]

现在,在公共资产文件夹中只有一个文件,其中包含最小化的所有补充文件内容。

编辑

Rails 默认预编译选项已更改为

[ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, /application.(css|js)$/ ]

因此带有额外句点的文件现在可以正确编译

The default precompile options work as long as you don't have any files with extra periods in them. like (jquery.treeview.js)

I was able to to get my assets to compile the way I wanted by explicitly defining the individual files that I wanted compiled.

 config.assets.precompile = [ 'application.css' ]

now in the public assets folder there is only one file that includes all the suplemental file content minimized.

EDIT

Rails default precomplie option has been changed to

[ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, /application.(css|js)$/ ]

so files with extra periods will compile properly now

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文