条件编译:
修改:build/webpack.dev.conf.js
new webpack.DefinePlugin({
'process.env': config.dev.env,
DEBUG: JSON.stringify(true),
}),
修改:build/webpack.prod.conf.js
new webpack.DefinePlugin({
'process.env': config.dev.env,
DEBUG: JSON.stringify(false),
}),
接下来就可以使用了:
if (DEBUG) {
console.log('this is dev env');
} else {
console.log('this is prod env');
}
去除不可达代码:
修改build/webpack.prod.conf.js:
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false, // 去除warning警告
dead_code: true, // 去除不可达代码
drop_debugger: true, // 去除debugger
drop_console: true, // 去除console
}
},
贴个好文地址