下面是我的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'
// }])
]
}
打包后就出现如下图错误
感谢问题找到了,是因为在第三行,我写了个process.env.NODE_ENV='prodction',
我想问一下,这是为什么呀?