Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding files from assets:precompile in rails

I use codekit for writing less which it then converts to css automatically.

I don't want rails to convert my less files to css, I rather codekit do it.

if I precompile the assets via

rake assets:precompile

I get

rake aborted!
cannot load such file -- less

How do I exclude a specific folder/file types from precompiling? (all my less files are in app/assets/stylesheets/less and the css (which I do want to be precompiled) are in app/assets/stylesheets/css

update

deleting application.less solves this but how do I excluding it from processing in the first place?

like image 980
Nick Ginanto Avatar asked Oct 17 '12 16:10

Nick Ginanto


People also ask

What is assets precompile in Rails?

4.1 Precompiling Assets. Rails comes bundled with a command to compile the asset manifests and other files in the pipeline. Compiled assets are written to the location specified in config.

What is assets Precompile?

rails assets:precompile is the task that does the compilation (concatenation, minification, and preprocessing). When the task is run, Rails first looks at the files in the config.assets.precompile array. By default, this array includes application.js and application.css .

How do I Precompile assets in Heroku?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.


2 Answers

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)$/ ]
like image 171
MrTheWalrus Avatar answered Oct 08 '22 02:10

MrTheWalrus


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.

like image 38
Kashyap Avatar answered Oct 08 '22 03:10

Kashyap