函数时:
``configureWebpack: (config) => {
let UglifyPlugin = require('uglifyjs-webpack-plugin');
if (process.env.NODE_ENV == 'production') {
// 为生产环境修改配置
config.mode = 'production'
// 将每个依赖包打包成单独的js文件
let optimization = {
minimizer: [new UglifyPlugin({
uglifyOptions: {
warnings: false,
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log']
}
}
})]
}
Object.assign(config, {
optimization
})
} else {
// 为开发环境修改配置
config.mode = 'development'
} },
对象时: configureWebpack: { // provide the app’s title in webpack’s name field, so that // it can be accessed in index.html to inject the correct title. name: name, resolve: { alias: { ‘@’: resolve(‘src’), ‘@crud’: resolve(‘src/components/Crud’) } } }, 如果需要结合使用: configureWebpack: (config) => {
config.name = name
config.resolve = {
...config.resolve,
alias: {
'@': resolve('src'),
'@crud': resolve('src/components/Crud')
}
}
// 引入uglifyjs-webpack-plugin
let UglifyPlugin = require('uglifyjs-webpack-plugin');
if (process.env.NODE_ENV == 'production') {
// 为生产环境修改配置
config.mode = 'production'
// 将每个依赖包打包成单独的js文件
let optimization = {
minimizer: [new UglifyPlugin({
uglifyOptions: {
warnings: false,
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log']
}
}
})]
}
Object.assign(config, {
optimization
})
} else {
// 为开发环境修改配置
config.mode = 'development'
} },
具体使用参考这位小哥,写的非常nice~: https://blog.csdn.net/lamianT/article/details/115527804?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2defaultCTRLISTRate-2-115527804-blog-103528594.pc_relevant_aa2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2defaultCTRLISTRate-2-115527804-blog-103528594.pc_relevant_aa2&utm_relevant_index=5
|