在webpack中定义生产配置时出现错误
错误:
Uncaught ReferenceError: process is not defined
类似的代码 console.log(进程)
process.env.NODE_ENV === "production"
if (process.env.NODE_ENV === "production") {
module.exports.devtool = "#source-map";
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: '"production"'
}
})
答案 0 :(得分:0)
当我添加Webpack.base.js时,它为我工作了-libraryTarget:'commonjs2'-例如更改自
(Webpack.js或Webpack.base.js或Webpack.config.js)
output: {
path: path.resolve(__dirname, "./dist"),
publicPath: "/dist/",
filename: "build.js"
}
到
output: {
path: path.resolve(__dirname, "./dist"),
publicPath: "/dist/",
filename: "build.js",
libraryTarget: 'commonjs2'
},
libraryTarget:'commonjs2'
//此选项允许用户在导出包装器中插入注释。要为每种libraryTarget类型插入相同的注释,请将assistantComment设置为字符串:
read more