Rails - sprockets 无法识别 scss 文件
Rails - sprockets cannot recognize scss files
我最近将我的 Sprockets 从 3.7.2 升级到 4.0.2,从那以后我的 application.css 文件无法识别用 scss 编写的文件之一:
*= require editor/content-tools.scss
*=/ require_tree .
*=/ require_self
*/
(editor/content-tools.scss 位于 vendor,不在 app/assets).
当我尝试执行它时收到此错误:
ActionView::Template::Error (couldn't find file 'editor/content-tools.scss' with type 'text/css'
Sprockets 正在寻找一个 'text/css' 类型的文件,如果我将我的文件重命名为 content-tools.css 它会停止产生错误,从而消除与路径查找相关的可能问题。
所以我的问题是如何让 sprockets 像以前一样在我的 application.css 中检查查找扩展名为 .scss 的文件?
Sprockets provides some directives that are placed inside of comments called require, require_tree, and require_self. DO NOT USE THEM IN YOUR SASS/SCSS FILES. They are very primitive and do not work well with Sass files. Instead, use Sass's native @import directive which sass-rails has customized to integrate with the conventions of your Rails projects.
因此您可以通过以下方式实现:
将 application.css
重命名为 application.scss
使用import
语法代替require
:
// application.scss
@import "editor/content-tools.scss";
@import "*";
我最近将我的 Sprockets 从 3.7.2 升级到 4.0.2,从那以后我的 application.css 文件无法识别用 scss 编写的文件之一:
*= require editor/content-tools.scss
*=/ require_tree .
*=/ require_self
*/
(editor/content-tools.scss 位于 vendor,不在 app/assets).
当我尝试执行它时收到此错误:
ActionView::Template::Error (couldn't find file 'editor/content-tools.scss' with type 'text/css'
Sprockets 正在寻找一个 'text/css' 类型的文件,如果我将我的文件重命名为 content-tools.css 它会停止产生错误,从而消除与路径查找相关的可能问题。
所以我的问题是如何让 sprockets 像以前一样在我的 application.css 中检查查找扩展名为 .scss 的文件?
Sprockets provides some directives that are placed inside of comments called require, require_tree, and require_self. DO NOT USE THEM IN YOUR SASS/SCSS FILES. They are very primitive and do not work well with Sass files. Instead, use Sass's native @import directive which sass-rails has customized to integrate with the conventions of your Rails projects.
因此您可以通过以下方式实现:
将
application.css
重命名为application.scss
使用
import
语法代替require
:
// application.scss
@import "editor/content-tools.scss";
@import "*";