# 熱重載
使用 webpack 的 [Hot Module Replacement API](https://webpack.js.org/guides/hot-module-replacement/),Vuex 支持在開發過程中熱重載 mutation、module、action 和 getter。你也可以在 Browserify 中使用 [browserify-hmr](https://github.com/AgentME/browserify-hmr/) 插件。
對于 mutation 和模塊,你需要使用 `store.hotUpdate()` 方法:
``` js
// 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) {
// 使 action 和 mutation 成為可熱重載模塊
module.hot.accept(['./mutations', './modules/a'], () => {
// 獲取更新后的模塊
// 因為 babel 6 的模塊編譯格式問題,這里需要加上 `.default`
const newMutations = require('./mutations').default
const newModuleA = require('./modules/a').default
// 加載新模塊
store.hotUpdate({
mutations: newMutations,
modules: {
a: newModuleA
}
})
})
}
```
參考熱重載示例 [counter-hot](https://github.com/vuejs/vuex/tree/dev/examples/counter-hot)。