We want to log out all the printing functions. It is certainly unrealistic to log out one by one. It is a waste of energy and time, and there will be omissions
Here we implement it with the help of uglifyjs-webpack-plugin
install
cnpm i uglifyjs-webpack-plugin --save-dev
vue.config.js
// vue.config.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
...
configureWebpack: config => {
if (process.env.NODE_ENV == 'production') {
config.mode = 'production'
config.optimization.minimizer = [
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false
},
// deleteconsole debugger
compress: {
warnings: false, // error
drop_console: true, // console
drop_debugger: false,
pure_funcs: ['console.log']// 移除console
}
}
})
]
} else {
config.mode = 'development'
}
}
...
}
warnings
is not a supported option
Here is a knowledge point. Warnings will report errors.
Some UglifyJsPlugin versions do not support setting the warnings parameter in the compress of the uglifyOptions object, but directly set warnings as a property in the uglifyOptions object.
If an error is reported. Then write warnings as the uglifyOptions attribute in the following way
// vue.config.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
...
configureWebpack: config => {
if (process.env.NODE_ENV == 'production') {
config.mode = 'production'
config.optimization.minimizer = [
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false
},
// delete console debugger
compress: {
drop_console: true, // console
drop_debugger: false,
pure_funcs: ['console.log']// remove console
},
warnings: false, // error
}
})
]
} else {
config.mode = 'development'
}
}
...
}
Read More:
- [Solved] error: Unexpected console statement (no-console)
- Solution to build error in Vue project (error in static/JS)/vendor.xxxxx.js from UglifyJs)
- error: Unexpected console statement (no-console) [How to Solve]
- Solve the problem of repeatedly clicking the same route console in Vue to report an error
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function
- [Solved] Vue uses webpack to package error: Createapp is not a function
- [Solved] Vue console error: navigationduplicated: avoided redundant navigation to current location
- [Solved] Vue Error: Module build failed: Error: No PostCSS Config found in
- [Solved] Vue Use gzip Package Error: Rule can only have one resource source
- [Solved] webpack Package Error: ERROR in multi ./src/main.js ./dist/bundle.js Module not found: Error: Can‘t resolv
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- [Solved] Vue calls style loader error: Module build failed: CssSyntaxError
- [Solved] Vue Error: Module build failed Error Node Sass version 6.0.1 is incompatible with ^4.0.0.
- When starting Vue project: cannot find module ‘webpack cli/bin/config yargs’ error resolution
- [Solved] Vue Route Error: Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function
- [Solved] Nuxt Import qrcodejs2.js / QRCode.js Error: document is not defined
- [Solved] ERROR Error loading vue.config.js: ERROR Error: Command failed: git describe
- Vue Use ‘npm run dev’ Error: Error: Unknown option ‘–inline‘ [How to Solve]
- [Solved] error:chunkgroup.addoptions:no option merge strategy for name
- [Solved] vite package Error: globalThis is not defined