2017-04-20 56 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

相关问题