Excluding files from assets:precompile in rails

假装没事ソ 提交于 2019-12-02 23:31:47

From the Asset Pipeline guide:

The default matcher for compiling files includes application.js, application.css and all non-JS/CSS files (i.e., .coffee and .scss files are not automatically included as they compile to JS/CSS):

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

If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array:

config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']

So, I would say that your solution is to modify config.assets.precompile to exclude .less files. Maybe something like this (in a suitable environment file, like config/environments/production.rb):

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

If your directory structure under the app/assets folder is so:

application.css
/css
 (generated by code kit)
 |...home.css
 |...index.css
/less
 |...home.less (assuming this is the extension)
 |...index.less

Then, in your application.css file, there must be a directive that says *= require_tree . This tells rails to scan all the files/directories and try to compile all the files into one css file.

Change this to *= require_directory ./css and it will load the files under the css directory for compilation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!