我想要实现的是:我有一个快速服务器,它在 webhook 上应该重新生成我的静态生成的 web 应用程序。我正在使用 webpack 来做到这一点。如果我从 webpack 的 CLI 生成静态站点,一切都像魅力一样。但是,如果我从节点内导入 webpack 配置,我会收到 Webpack 选项验证错误:
- configuration.module.rules[4].loader should be one of these:
non-empty string | non-empty string | function | object { loader?, options?, query? } | function | [non-empty string | function | object { loader?, options?, query? }]
调试了一下,我发现在我使用WebpackExtractTextPlugin的地方添加了一个加载器,即加载器:
{ loader: 1178, options: [Object] }
这是我共享的 webpack.js 的样子:
module.exports = (env) => ({
context : path.resolve(__dirname, '..', 'entries'),
output : {
path : path.resolve(__dirname, '..', '..', 'build'),
filename : '[name].js',
publicPath : '/'
},
plugins : [
new webpack.EnvironmentPlugin({
// ...
}),
],
module : {
rules : [
{
test : /\.js$/,
loader : 'babel-loader',
exclude : /node_modules/,
options : {
babelrc : false,
presets : ['es2015', 'stage-0', 'react'],
}
},
{
test : /\.json$/,
loader : 'json-loader'
},
{
test : /\.(jpg|jpeg|png|gif|ico)$/,
loader : 'file-loader?name=img/[name].[ext]'
},
{
test : /\.svg$/,
loader : 'file-loader?name=svg/[name].[ext]'
},
{
test : /\.less$/,
loader : ExtractTextPlugin.extract({
fallback : 'style-loader',
use : [
{
loader : 'css-loader',
options : {
importLoaders : 1,
modules : true,
minimize : env !== 'dev',
sourceMap : env === 'dev',
discardComments : { removeAll : true },
localIdentName : env === 'dev' ? '[path][name]-[local]-[hash:base64:3]' : '[hash:base64:5]'
}
},
{
loader : 'less-loader',
options : {
sourceMap : env === 'dev',
modifyVars : lessConfig
}
}
]
})
},
{
test : /\.css$/,
loader : ExtractTextPlugin.extract({
fallback : 'style-loader',
use : {
loader : 'css-loader',
options : {
minimize : env !== 'dev',
sourceMap : env === 'dev'
}
}
})
}
]
},
// ...
})
我webpack.static.js
将上述内容与此合并:
module.exports = (env) => merge.smart(webpackConfig(env), {
entry : {
static : [
'babel-polyfill',
'./static'
]
},
output : {
path : path.resolve(__dirname, '..', '..', 'build', 'static'),
libraryTarget : 'umd',
publicPath : '/'
},
externals : vendorConfig,
plugins : [
new ProgressBarPlugin(),
new ExtractTextPlugin({
filename : 'client.css',
allChunks : true
}),
new StaticSiteGeneratorPlugin({ paths })
],
module : {
rules : [
{
test : /\.js$/,
loader : 'babel-loader',
query : {
presets : ['es2015', 'stage-0', 'react'],
plugins : ['system-import-transformer']
}
}
]
},
target : 'node'
})
有谁知道那个额外的装载机可能来自哪里,或者我做错了什么来结束这个问题?
我正在使用:webpack@2.2.1 extract-text-webpack-plugin@2.1.0