Rails 3.1 自定义 sprockets 预编译资源
我正在尝试自定义预编译哪些资产。在生产中,我只希望编译 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 sprockets 文档,它非常广泛且写得很好。
对于您的特定问题,以下
application.css
将仅递归地包含components/form_elements
和components/lists
目录:如果
form_elements
和lists
是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 thecomponents/form_elements
andcomponents/lists
directories, recursively:If
form_elements
andlists
are css files, just replacerequire_tree
withrequire
.只要您没有任何包含额外句点的文件,默认的预编译选项就会起作用。像(jquery.treeview.js)一样,
我能够通过显式定义我想要编译的各个文件来让我的资产按照我想要的方式进行编译。
现在,在公共资产文件夹中只有一个文件,其中包含最小化的所有补充文件内容。
编辑
Rails 默认预编译选项已更改为
因此带有额外句点的文件现在可以正确编译
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.
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
so files with extra periods will compile properly now