Rails资产管道与sass @imports [重复]

时间:2021-10-01 09:47:59

This question already has an answer here:

这个问题在这里已有答案:

I'm using Rails 4.2.

我正在使用Rails 4.2。

In my rails project directory, I have a frontend directory:

在我的rails项目目录中,我有一个前端目录:

/railsproject/frontend
/railsproject/frontend/styles
/railsproject/frontend/styles/main.scss
/railsproject/frontend/styles/variables.scss
/railsproject/frontend/node_modules/normalize.css/
/railsproject/frontend/node_modules/normalize.css/normalize.css

(I know it's unusual to have a directory with a period in it, but I have tried changing the directory name and corresponding @import statement and it didn't make a difference)

(我知道有一个带有句点的目录是不寻常的,但我已经尝试更改目录名和相应的@import语句,但没有区别)

I have added config.assets.paths << Rails.root.join("frontend","styles") to application.rb.

我已将config.assets.paths << Rails.root.join(“frontend”,“styles”)添加到application.rb。

In /railsproject/app/assets/stylesheets/application.css:

@import "main.scss";

Everything is good so far, it loads/processes the main.scss file.

到目前为止一切都很好,它加载/处理main.scss文件。

In /railsproject/frontend/styles/main.scss

@import 'variables'; // this works fine
@import '../node_modules/normalize.css/normalize.css'; // this does NOT work

The second import doesn't work...I get a GET error in the Chrome console, and the rails server says:

第二次导入不起作用...我在Chrome控制台中收到GET错误,并且rails服务器说:

Started GET "/node_modules/normalize.css/normalize.css" for ::1 at 2015-07-02 15:55:38 +0800

ActionController::RoutingError (No route matches [GET] "/node_modules/normalize.css/normalize.css"):

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


-1  

SASS is not letting you import CSS files, it wants SCSS files to compile into CSS. Either switch your file extension to SCSS or upgrade to SASS 3.2.10 which is supposed to let you import CSS files.

SASS不允许你导入CSS文件,它希望SCSS文件编译成CSS。将文件扩展名切换到SCSS或升级到SASS 3.2.10,它可以让您导入CSS文件。

Reference: Import regular CSS file in SCSS file?

参考:在SCSS文件中导入常规CSS文件?

#1


-1  

SASS is not letting you import CSS files, it wants SCSS files to compile into CSS. Either switch your file extension to SCSS or upgrade to SASS 3.2.10 which is supposed to let you import CSS files.

SASS不允许你导入CSS文件,它希望SCSS文件编译成CSS。将文件扩展名切换到SCSS或升级到SASS 3.2.10,它可以让您导入CSS文件。

Reference: Import regular CSS file in SCSS file?

参考:在SCSS文件中导入常规CSS文件?