Search code examples
ruby-on-railsrubyruby-on-rails-4asset-pipelineprecompile

precompile assets - rails 4.1.1


I'm setting up first ruby site in production, everything works ok, but when I run

rake assets:precompile

It adds the css/js in "public/assets/" directory ok, but they have paths and line numbers in the files? So was just wondering how to get it all on one line and without line numbers/comments? Have I missed a setting or anything for this? Here is an example of how my application-428d86248ca363.css comes out:

/* line 1, /home/joe/myapp/app/assets/stylesheets/main.scss */
body {
  background: #ccc;
}

/* line 6, /home/joe/myapp/app/assets/stylesheets/main.scss */
#head {
  background: #666;
}
/* line 4, /home/joe/myapp/app/assets/stylesheets/welcome.css.scss */
.block {
  color: #1e1e1e;
}
/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any styles
 * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
 * file per style scope.
 *
 */

Also you can see it includes the big comment at end. How do I get it to go all on one line with no comments?


Solution

  • SCSS

    they have paths and line numbers in the files

    That's a problem with SCSS which should resolve if you use rake assets:precompile RAILS_ENV=production


    Fix

    Whilst looking for a reference, I found this answer and this github:

    Just to update previous answer, by Chase T.
    
    For me this is not working anymore.
    
         #config/compass.rb
         line_comments = false
    
    should become
    
         line_comments = 0
    

    Considering the resource uses compass.rb, I looked to see how to do it in a standard Rails app. I found the way to do it is to use a system, and looks like you can use this command:

    #config/application.rb
    config.sass.line_comments = false
    

    This is confirmed with this information:

    Using Rails 4.1 and after looking and looking (and possibly misreading the documentation) I got this to work by adding the following to /config/environments/development.rd & production.rb

    config.sass.preferred_syntax = :scss

    config.sass.style = :compact

    config.sass.line_comments = false

    Style can be set to :nested, :expanded, :compact, :compressed. You can see the different options here: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#output_style

    Also, make sure to restart your server to see the compiled version change

    Hope this helps someone.