预编译资产 - rails 4.1.1

时间:2014-05-29 22:55:52

标签: ruby-on-rails ruby ruby-on-rails-4 asset-pipeline precompile

我正在制作第一个ruby网站,一切正常,但是当我运行时

rake assets:precompile

它在“public / assets /”目录中添加了css / js,但它们在文件中有路径和行号吗?所以只是想知道如何在一条线上并且没有行号/注释?我错过了设置或其他任何内容吗?以下是我的application-428d86248ca363.css如何出现的示例:

/* 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.
 *
 */

另外你可以看到它包括最后的重要评论。如何让它在一行中没有注释?

1 个答案:

答案 0 :(得分:1)

<强> SCSS

  

他们在文件中有路径和行号

如果您使用rake assets:precompile RAILS_ENV=production

解决SCSS的问题

<强>修正

在寻找参考资料时,我找到了this answerthis 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

考虑到资源使用compass.rb,我看看如何在标准的Rails应用程序中执行此操作。我发现这样做的方法是使用系统,看起来你可以使用这个命令:

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

这已通过this information确认:

  

使用Rails 4.1以及查看和查找(并可能误读   文档)我通过添加以下内容来实现此目的   /config/environments/development.rd & production.rb

     

config.sass.preferred_syntax = :scss

     

config.sass.style = :compact

     

config.sass.line_comments = false

     

样式可以设置为:嵌套,   :扩展,:紧凑,:压缩。您可以看到不同的选项   这里:   http://sass-lang.com/documentation/file.SASS_REFERENCE.html#output_style

     

此外,请确保重新启动服务器以查看已编译的版本   变化

     

希望这有助于某人。