Hot Reloading

NOTE

The following documentation comes directly from the vuex.vuejs.org.

Vuex supports hot-reloading mutations, modules, actions and getters during development, using webpack's Hot Module Replacement API. You can also use it in Browserify with the browserify-hmr plugin.

For mutations and modules, you need to use the store.hotUpdate() API method:

// store.js
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import moduleA from './modules/a'

Vue.use(Vuex)

const state = { ... }

const store = new Vuex.Store({
  state,
  mutations,
  modules: {
    a: moduleA
  }
})

if (module.hot) {
  // accept actions and mutations as hot modules
  module.hot.accept(['./mutations', './modules/a'], () => {
    // require the updated modules
    // have to add .default here due to babel 6 module output
    const newMutations = require('./mutations').default
    const newModuleA = require('./modules/a').default
    // swap in the new modules and mutations
    store.hotUpdate({
      mutations: newMutations,
      modules: {
        a: newModuleA
      }
    })
  })
}

Checkout the counter-hot example to play with hot-reload.