webpack打包提示ERROR in main.js from Terser Invalid assignment
下面是我的webpack.config.js配置文件代码
const path = require('path')
const webpack = require('webpack')
const npm_package = require('./package.json')
const _externals = require('externals-dependencies')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
function resolve(dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
mode: 'production',
devtool: 'source-map',
cache: true,
entry: ['babel-polyfill', './src/app.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/dist',
chunkFilename: 'js/[id].chunk.js'
},
resolve: {
extensions: ['.js', '.json'],
alias: npm_package._moduleAliases || {
'@': resolve('src')
},
modules: npm_package._moduleDirectories || []
},
target: 'node',
externals: [_externals(), nodeExternals()],
context: __dirname,
node: {
console: true,
global: true,
process: true,
Buffer: true,
__filename: true,
__dirname: true,
setImmediate: true,
path: true
},
module: {
rules: [{
test: /\.js/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: ['es2015', 'env'],
plugins: ['transform-runtime', 'transform-object-rest-spread']
}
}
}]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})
// new CopyWebpackPlugin(\[{
// from: path.resolve(__dirname, '/config/config.js'),
// toType: 'file'
// },{
// from: path.resolve(__dirname, '/config/baseConfig.js'),
// toType: 'file'
// }])
]
}
打包后就出现如下图错误
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
感谢问题找到了,是因为在第三行,我写了个process.env.NODE_ENV='prodction',
我想问一下,这是为什么呀?
这里说的是赋值无效,检查你的代码,config.js的第3行和main的第568行,看看有没有赋值问题,比如if语句里面写了==写成了=;
遇到同样的问题 也是process.env.NODE_ENV赋值报错