开发者

rails 3.1 customize sprockets precompile assets

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 hav开发者_高级运维e a file like form.elements.js sprockets will precompile it thinking it is a non js/css file.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜