Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I minify CSS in Rails 4?

I tried the following, however I look at the CSS source and it does not minify! I restarted the server several dozen times. I turned off cache in the browser. I also tried the 'yui-compressor' gem.

config/environments/development.rb

  config.assets.debug = false
  config.assets.css_compressor = :sass
  config.assets.compile = true

Gemfile

group :assets do
  # Add any compass extensions here
  # Use SCSS for stylesheets
  gem 'sass-rails', '~> 4.0.0'

Reference

http://edgeguides.rubyonrails.org/asset_pipeline.html#customizing-the-pipeline

Version

WEBrick 1.3.1, ruby 2.0.0 (2013-06-27) [i386-mingw32], Rails 4.0.3

like image 228
Chloe Avatar asked Mar 06 '14 05:03

Chloe


People also ask

How do you Precompile in Rails?

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.


1 Answers

I was having the same problem in my production environment, where I couldn't get the CSS to minify upon deploying to Heroku. After turning on compression with the following:

production.rb

config.assets.css_compressor = :sass

Gemfile

gem 'sass-rails', '~> 4.0.0'    

I managed to get it to minify by updating the assets version:

production.rb

config.assets.version = '1.1' # was '1.0'

Doing a few tests afterwards, I found that updating the source CSS/SASS had the same effect. So try updating your stylesheets (as opposed to only the config), which should "kickstart" the minification process when Heroku precompiles your assets after you push, without needing to update the assets version.

like image 50
jonalport Avatar answered Sep 23 '22 17:09

jonalport