Webpack - 无法找到SASS / SCSS的加载程序

时间:2016-12-22 11:24:11

标签: angular sass webpack

我收到错误消息:

ERROR in ./src/assets/css/site.scss
Module parse failed: C:\_Code\vscode\angular2-webpack-starter\src\assets\css\site.scss Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @import "_variables.scss";
| @import "_helpers.scss";
| html {
 @ ./src/app/app.component.ts 5:0-34
 @ ./src/app/app.module.ts


module: {
        loaders: [
        {
            test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
            loader: "url?limit=10000&minetype=application/font-woff"
        }, {
            test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
            loader: "url?limit=10000&minetype=application/font-woff"
        }, {
            test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
            loader: "url?limit=10000&minetype=application/octet-stream"
        }, {
            test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
            loader: "file"
        }, {
            test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
            loader: "url?limit=10000&minetype=image/svg+xml"
        },{
            test: /\.sass$/,
            loaders: ["style", "css", "sass"]
        }
       ,{
            test: /\.scss$/,
            loaders: ["style", "css", "sass"]
        }], 
        rules:[...]
      //Other random code from webpack starter kit

};

以下代码可以正常使用

//Works    
require("!style-loader!css-loader!sass-loader!../assets/css/site.scss");
//Doesn't work
require('../assets/css/site.scss');

已经尝试过以下配置选项

{test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"]}

loaders: ["style", "css", "sass"]
loader: '!style-loader!css-loader!sass-loader!'
loader: 'style-loader!css-loader!sass-loader'

我想从webpack配置加载,但似乎没有工作。该项目实际上是整个Angular 2 webpack启动器。

正确的软件包都是作为依赖项安装的,我已经阅读了我可以在Google上找到的教程和解决方案。

1 个答案:

答案 0 :(得分:1)

这就是我正在使用它的工作原理:

        {
            test: /\.scss$/,
            use: ['to-string-loader', 'css-loader', 'sass-loader']
        },

并安装

"style-loader
"to-string-loader
"sass-loader
"node-sass
"css-loader