【发布时间】:2017-09-07 20:49:46
【问题描述】:
我试图包含 .scss 文件它总是抛出这个错误:
Expected 'styles' to be an array of string
以前当我使用 webpack 1 时一切正常,我尝试了 3 种不同的方法,但没有一种方法有效:
1. styles: [require('../../../static/v4/angular/scss/main.scss')]
2. styles: [String(require('../../../static/v4/angular/scss/main.scss'))]
1. styles: [require('../../../static/v4/angular/scss/main.scss').toString()]
这是我的装载机:
{
test: /\.css$/,
exclude: helpers.root('src', 'app'),
loader: ExtractTextPlugin.extract({fallback: 'style-loader', loader: 'css-loader'})
},
{
test: /\.css$/,
include: helpers.root('src', 'app'),
use: [{loader: 'raw-loader'}]
}, {
test: /\.scss$/,
exclude: /node_modules/,
use: [{
loader: "to-string-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
}]
}, {
【问题讨论】:
-
您是否尝试过映射回生成的源?
styles: [require('../../../static/v4/angular/scss/main.scss')]应该是正确的,但是如果有一些配置错误,它可以是未定义的。 -
@TatsuyukiIshi 你所说的
map back to the generated source是什么意思,如果你在谈论路径,那么路径是正确的,因为它之前在 webpack 1 中工作 -
请检查 webpack 的输出,这看起来像是运行时错误。
-
在运行 npm run build 时出现错误,所以没有输出
-
尝试在
styles: [require('./../../../static/v4/angular/scss/main.scss')]之前使用./