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)
- [Solved] Vue Error: error: ‘to‘ is defined but never used (no-unused-vars)
- [Solved] Vue2.0 Error: Syntax Error: TypeError: eslint.CLIEngine is not a constructor
- Solution to some map files in JS folder after Vue packaging (remove the map. JS file)
- NPM publish an angular library Error [How to Solve]
- vue-elemnt-admin npm run dev [How to Solve]
- How to Solve VUE Error: Mixed spaces and tabs
- [Solved] Vue Project startup error: no eslint configuration found
- Vue-cli2 sub environment packaging
- JS to determine whether the string contains a character
- JS uses onerror to automatically catch exceptions
- [Solved] Vue eslint Error: Component name “*****“ should always be multi-word
- [Solved] Errors: 1 http://eslint.org/docs/rules/quotes…elementUI Import Error
- VUE Error: Mixed spaces and tabs [How to Solve]
- [Solved] Vue item packaging error: Failed to load resource: the server responded with a status of 404 (Not Found)
- for..in loops iterate over the entire prototype chain, which is virtually never what you want.
- [Solved] Error spawn CMD enoent errno when starting Vue project: – 4058
- xxx is assigned a value but never used [How to Solve]
- [Solved] ESLint error: Newline required at end of file but not found (eol-last)
- [Solved] Failed to load plugin ‘vue‘ declared in ‘.eslintrc.js‘: createRequire is not a function