The scene that
Console. log is commonly used for debugging during project development. After development, remove console.log or ignore console.log in the code before deploying it online
The solution
- By configuring plug-ins, for example
uglifyjs-webpack-plugin
(Slow packing) - Solve for yourself: Rewrite
console.log
Method (does not affect packaging speed)
Since the company project uses vue-cli2, all things considered, rewrite the console.log method; In the code
function rewirteLog() {
console.log = (function (log) {
return process.env.NODE_ENV == 'production' ? function () { } : log
}(console.log))
}
Copy the code
steps
- Write a method to determine if it is a production environment and override it if it is
console.log
Methods; - in
main.js
File to call this method
Write in the last
My name is AndyHu and I am currently working as a front-end brick moving engineer.
If there are any mistakes in this article, please correct them in the comments section. If this article helps you, please like it and follow it
Let the soul control its own skin. Thus more freedom!!