2017-04-20 20 views
2

的application.js我有一個奇怪的困惑,當我使用的application.js在軌像爲什麼所有的意見都沒有application.css.scss的影響,在軌

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

,並使用application.css。這樣

/* 

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

我覺得// SCSS是在js文件的註釋和/ * * /也是在CSS文件中的評論,我沒有想太多,只使用過,但現在我想知道爲什麼js和css文件中的所有註釋都對rails沒有影響?

+0

我不知道Ruby,但快速谷歌搜索帶'<%# %>'作爲評論。 – Christoph

回答

2

是的,無論是///* */分別爲jscss文件的意見,但//=*=是由sprockets使用的指令,從docs

DirectiveProcessor負責分析和評估 指導意見在源文件中。

指令註釋以註釋前綴開頭,後跟「=」, ,然後是指令名稱,然後是任何參數。

// JavaScript 
//= require "foo" 

# CoffeeScript 
#= require "bar" 

/* CSS 
*= require "baz" 
*/ 

所以js.css文件將把//=*=作爲註釋,但sprockets會讀這些指令將所需的文件加載到軌資產的管道。

查看sprockets guides瞭解更多詳細信息。

+0

我突然變得清醒了,謝謝。 – Tsao

相關問題