Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack vue cli clear browser console on reload

Tags:

vue.js

vue-cli

using the vue-cli-service which uses webpack under the hood, is there a way to set things up so on hot reload the browsers console is cleared?

It is not very efficient to constantly see old messages in the console log that are not relevant to the current state of the app on last save.


1 Answers

Simple keep clearing the console every time a hot reload happen by adding this to the main.js file

if (module.hot) {
    module.hot.accept() // already had this init code 

    module.hot.addStatusHandler(status => {
        if (status === 'prepare') console.clear()
    })
}

main.js file now would be

import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

new Vue({
  render: h => h(App)
}).$mount('#app')

if (module.hot) {
    module.hot.accept() // already had this init code 

    module.hot.addStatusHandler(status => {
        if (status === 'prepare') console.clear()
    })
}
like image 116
Vigneshwaran Avatar answered Nov 25 '25 00:11

Vigneshwaran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!