由于配置对象与API架构不匹配,因此无法构建生产模式。将webpack@3.0.0更新到版本webpack@4.40.2后发生了错误。我更新了webpack版本,因为extract-text-webpack-plugin与webpack@3.0.0不兼容。
以下是我运行纱线运行build:prod(生产模式)时的终端错误
下面是webpack.config.js文件
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = (env)=>{
const isProduction = env === 'production';
const CSSExtract = new ExtractTextPlugin('styles.css');
console.log('env', env);
return {
entry: './src/app.js',
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js'
},
module: {
rules: [{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
},{
test: /\.s?css$/,
use: CSSExtract.extract({
use: [
'css-loader',
'sass-loader'
]
})
}]
},
plugin: [
CSSExtract
],
devtool: isProduction ? 'source-map' : 'cheap-module-eval-source-map',
devServer: {
contentBase: path.join(__dirname, 'public'),
historyApiFallback: true
}
}
};
下面是package.json文件
{
"name": "expensify-app",
"version": "1.0.0",
"main": "index.js",
"author": "Andrew Mead",
"license": "MIT",
"scripts": {
"serve": "live-server public/",
"build:dev": "webpack",
"build:prod": "webpack -p --env production",
"dev-server": "webpack-dev-server",
"test": "jest"
},
"dependencies": {
"babel-cli": "6.24.1",
"babel-core": "6.25.0",
"babel-loader": "7.1.1",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "1.5.2",
"babel-preset-react": "6.24.1",
"css-loader": "0.28.4",
"enzyme": "3.0.0",
"enzyme-adapter-react-16": "1.0.0",
"jest": "20.0.4",
"live-server": "^1.2.0",
"moment": "^2.24.0",
"node-sass": "4.5.3",
"normalize.css": "7.0.0",
"npm": "^6.11.3",
"raf": "3.3.2",
"react": "16.0.0",
"react-addons-shallow-compare": "^15.6.2",
"react-dates": "^21.1.0",
"react-dom": "16.0.0",
"react-modal": "2.2.2",
"react-redux": "5.0.5",
"react-router-dom": "^5.0.1",
"react-test-renderer": "16.0.0",
"redux": "^4.0.4",
"sass-loader": "6.0.6",
"style-loader": "0.18.2",
"uuid": "^3.3.3",
"validator": "8.0.0",
"webpack": "^4.40.2",
"webpack-dev-server": "2.5.1"
},
"devDependencies": {
"extract-text-webpack-plugin": "^3.0.2",
"webpack-cli": "^3.3.9"
}
}
答案 0 :(得分:1)
在您的Webpack配置中将“插件”更改为“插件”