为什么所有注释都不会影响rails.css.scss和application.js

时间:2017-04-20 15:40:39

标签: javascript css ruby-on-rails comments

当我在像这样的轨道中使用application.js时,我有一个奇怪的混乱

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
//= require underscore
//= require gmaps/google

并像那样使用application.css.scss

/*

 * 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 any plugin's vendor/assets/stylesheets directory 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.
 *
 *= require_tree .
 *= require_self
 */

我认为//是js文件中的注释,/ * * /也是css文件中的注释,我没有想太多而只是之前使用过,但是现在我想知道为什么所有注释都在js和css文件在rails中没有效果?

1 个答案:

答案 0 :(得分:3)

是的,///* */分别是jscss文件的评论,但//=*=是指令使用的来自docs

sprockets
  

DirectiveProcessor负责解析和评估   源文件中的指令注释。

     

指令注释以注释前缀开头,后跟“=”,   那么指令名,然后是任何参数。

// JavaScript
//= require "foo"

# CoffeeScript
#= require "bar"

/* CSS
 *= require "baz"
 */

因此,js.css文件会将//=*=视为注释,但sprockets会读取这些指令以将所需文件加载到rails中资产管道。

另请查看sprockets guides以获取更多详细信息。