我正在使用此处文档中的方法测试dev / prod配置文件https://webpack.js.org/guides/production/#simple-approach
但是当我将基本配置切换为函数时,我收到以下错误WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration should be an object.
我正在使用webpack 3.0.0
原始webpack.config.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: [
'webpack/hot/dev-server',
'webpack-hot-middleware/client',
'./src/index.js'
],
output: {
publicPath: '/',
path: path.join(__dirname, 'build/static'),
filename: 'jb.js'
},
watch: true,
module: {
loaders: [
{
test: /\.js$/,
loaders: ['react-hot-loader', 'babel-loader'],
exclude: /node_modules/,
include: __dirname
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin({
// exclude hot-update files
test: /^(?!.*(hot)).*/
})
]
}
将基本配置作为功能
const path = require('path');
const webpack = require('webpack');
module.exports = (env) => {
return {
entry: [
'webpack/hot/dev-server',
'webpack-hot-middleware/client',
'./src/index.js'
],
output: {
publicPath: '/',
path: path.join(__dirname, 'build/static'),
filename: 'jb.js'
},
watch: true,
module: {
loaders: [
{
test: /\.js$/,
loaders: ['react-hot-loader', 'babel-loader'],
exclude: /node_modules/,
include: __dirname
}
]
},
plugins: [
new webpack.HotModuleReplacementPlugin({
test: /^(?!.*(hot)).*/
})
]
}
}