How enable console log in VUE-CLI during development

Aliosh r

I have been trying to figure out how to console.log('whatever') during learning some VueJs development in my methods in order to understand some behaviour of whatever I am doing here.

I understand that there're some questions already asked here and have scoped into ESLINT documentation to try an figure this out... I just can't actually understand what I should do.

My code:

methods: {
    submitData() {
        this.$http.post('https://vue-testing-8a2de.firebaseio.com/data.json', this.user)
                  .then(response => {
                            console.log(response);
                        }, error => {
                            console.log(error)
                        })
    }
}

This is the error on ESLINT:

Failed to compile.

./src/App.vue
Module Error (from ./node_modules/eslint-loader/index.js):
error: Unexpected console statement (no-console) at src/App.vue:35:22:
  33 | this.$http.post('https://vue-testing-8a2de.firebaseio.com/data.json',this.user)
  34 |           .then(response => {
> 35 |                      console.log(response);
     |                      ^
  36 |                  }, error => {
  37 |                      console.log(error)
  38 |                  })


error: Unexpected console statement (no-console) at src/App.vue:37:22:
  35 |                      console.log(response);
  36 |                  }, error => {
> 37 |                      console.log(error)
     |                      ^
  38 |                  })
  39 |             }
  40 |         }


2 errors found.

I have looked into this website:

I tried commenting the previous line before console.log:

  • /*eslint no-console: "error"*/ (but it doesn't works well)

I need a step by step guide if I need to mess with JSON rules, as I have never done this before.

I am using vue-cli on WebStorm.

Thanks in advance!

Jaromanda X

Edit package.json and in eslintConfig property add

"eslintConfig": { // don't add this, it's already there
    // there's stuff here
    "rules": { // find the rules property
    // addition starts here
        "no-console": "off"
    // addition ends here
    },
    // and keep what was already here

Now, if you want console.log stripped from production build

Edit vue.config.js

and add

// addition starts here
const TerserPlugin = require('terser-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
// addition ends here

module.exports = {
    // addition starts here
    configureWebpack: {
        optimization: {
            minimize: true,
            minimizer: isProd ? [
                new TerserPlugin({
                    terserOptions: {
                        ecma: 6,
                        compress: { drop_console: true },
                        output: { comments: false, beautify: false }
                    }
                })
            ] : []
        }
    },
    // addition ends here
    // and keep what was already here
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to enable console.log in ExtJs

vuejs vue-cli how can I use console.log without getting any errors

How can I make console.log() work in a Vue-cli app?

vue cli inspecting css from browser development console

Vue CLI 3 remove console.log and code comments with Terser

How console log element value during map() in javascript?

How to initialize Vue-CLI app with data during created() hook?

how can I enable/ disable console.log from the browser console

How can I handle redirects in vue cli development server with a proxy?

How to bind console.log to "l" in vue.js?

How to console.log an item inside a v-for loop in Vue

Jenkins Pipeline: Enable timestamps in build log console

How to enable email and password signin provider for new firebase project using gcloud console or firebase tools CLI?

vue cli3 enable CORS

Enable (console) logging of router events in Vue

How to print logs during jest tests when I need to mock console.log as part of testing?

Vue cli delete the outputDir folder during serve

How to enable color for PHP CLI?

Angular console log only on development environment

how to open CLI during installation

How to log to file and to console

How to console log a promise?

Is it ok to enable proposed updates during Ubuntu's development cycle?

How to disable Crashlytics during development

How to structure a package during development?

How Can I Change [Array] or [Object] In My CLI Console Log To The Full Values?

How to enable MySQL Query Log?

How to Enable query log in Laravel?

Vue v-for output to console.log