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 exampleuglifyjs-webpack-plugin(Slow packing)
  • Solve for yourself: Rewriteconsole.logMethod (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

  1. Write a method to determine if it is a production environment and override it if it isconsole.logMethods;
  2. inmain.jsFile 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!!