参考:
vue cli 3.0 文件压缩如何去掉console.log
在vue.config.js 最上方require这个插件。
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
不生效啊
看代码:
参考:
vue cli 3.0 文件压缩如何去掉console.log
在vue.config.js 最上方require这个插件。
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
看代码:
config.optimization.minimizer([
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
drop_console: true, // console
pure_funcs: ['console.log'] // 移除console
}
}
})
])
参考https://github.com/vuejs/vue-...
尝试将你的代码new UglifyJsPlugin(...)部分改成下面的
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
configureWebpack({
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: { drop_console: true }
}
})
]
}
})
}
module.exports = {
// Project deployment base
// By default we assume your app will be deployed at the root of a domain,
// e.g. https://www.my-app.com/
// If your app is deployed at a sub-path, you will need to specify that
// sub-path here. For example, if your app is deployed at
// https://www.foobar.com/my-app/
// then change this to '/my-app/'
//baseUrl: BASE_URL,
//baseUrl写法过期了
publicPath: BASE_URL,
// tweak internal webpack configuration.
// see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
// 如果你不需要使用eslint,把lintOnSave设为false即可
lintOnSave: false,
chainWebpack: config => {
config.resolve.alias
.set('@', resolve('src')) // key,value自行定义,比如.set('@@', resolve('src/components'))
.set('_c', resolve('src/components'))
.set('vue$','vue/dist/vue.esm.js')
if (process.env.NODE_ENV === 'production') {
// 为生产环境修改配置...
// 用来打包删除所有config以及debugger,true打开
config.optimization
.minimizer[
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
drop_console: true, // console
drop_debugger: false,
pure_funcs: ['console.log']// 移除console
}
}
})
]
} else {
// 为开发环境修改配置...
}
},
// 打包时不生成.map文件
productionSourceMap: false
// 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
// devServer: {
// proxy: 'localhost:3000'
// }
}
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
configureWebpack: config => {
if (process.env.NODE_ENV === "production") {
// 为生产环境修改配置...
config.mode = "production";
config.optimization.minimizer[
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
drop_console: true, //console
drop_debugger: true,
pure_funcs: ['console.log'] //移除console
}
}
})
]
} else {
// 为开发环境修改配置...
config.mode = "development";
}
}
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
}
}
8 回答5.8k 阅读✓ 已解决
9 回答9.2k 阅读
6 回答4.8k 阅读✓ 已解决
5 回答3.5k 阅读✓ 已解决
4 回答7.9k 阅读✓ 已解决
7 回答9.8k 阅读
5 回答7.1k 阅读✓ 已解决
楼主试试这个