Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  4] [ 5]  / answers: 1 / hits: 6575  / 4 Years ago, sun, october 18, 2020, 12:00:00

I am looking for a way to disable console.log() for production env. Something like putting the below code to nuxt.config.js or index.js:


if (process.env.NODE_ENV !== "development") {
console.log = () => {};
}

I tried it, but it doesn't work. Any help would be appreciated.


My nuxt.config.js is here
https://gist.github.com/somaria/9a2b0e06497d13a35fe9eee141a15d07


More From » vue.js

 Answers
14

Nuxt's build process includes terser, which can be configured to automatically remove console statements from your production build. You could set build.terser.terserOptions:


// nuxt.config.js
export default {
build: {
terser: {
// https://github.com/terser/terser#compress-options
terserOptions: {
compress: {
drop_console: true
}
}
}
}
}

[#2467] Tuesday, October 13, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaleyv

Total Points: 259
Total Questions: 99
Total Answers: 107

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;