我正在使用Webpack Validator来验证我的Webpack Config对象,并且它给了我以下错误:
[1] "loader" must be a string
这是我的Webpack配置对象:
const config = webpackValidator({
context: resolve('client'),
entry: {
app: './app.js',
vendor: ['./app.css'],
},
output: {
filename: ifProd('bundle.[name].[chunkhash].js', 'bundle.[name].js'),
path: resolve('dist'),
pathinfo: ifNotProd(),
},
devtool: ifProd('source-map', 'eval'),
module: {
loaders: [
{test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/},
{test: /\.jsx$/, loaders: ['babel-loader'], exclude: /node_modules/},
{
test: /\.css$/, loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader'
})
},
],
},
plugins: removeEmpty([
new ProgressBarPlugin(),
new ExtractTextPlugin(ifProd('styles.[name].[chunkhash.css]', 'styles.[name].css')),
ifProd(new InlineManifestWebpackPlugin()),
ifProd(new webpack.optimize.CommonsChunkPlugin({
name: ['vendor', 'manifest'],
})),
new HtmlWebpackPlugin({
template: './index.html',
inject: 'head',
}),
]),
})
非常感谢任何见解!
答案 0 :(得分:0)
“模块”的第一个属性是加载程序,而规则应该是规则。
module: {
rules: [{
test: /\.js$/,
loaders: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.jsx$/,
loaders: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: 'css-loader'
})
},
],
},
此外,为了避免重复,两个第一个代码规则可以与
test: /\.(jsx|js)$/