2017-08-22 07:43:34 +00:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
import getters from './getters'
|
2017-04-18 07:09:13 +00:00
|
|
|
|
2017-08-22 07:43:34 +00:00
|
|
|
Vue.use(Vuex)
|
2017-04-18 07:09:13 +00:00
|
|
|
|
2019-04-04 06:37:01 +00:00
|
|
|
// https://webpack.js.org/guides/dependency-management/#requirecontext
|
|
|
|
const modulesFiles = require.context('./modules', false, /\.js$/)
|
|
|
|
|
|
|
|
// you do not need `import app from './modules/app'`
|
|
|
|
// it will auto require all vuex module from modules file
|
|
|
|
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
|
|
|
|
// set './app.js' => 'app'
|
|
|
|
const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
|
|
|
|
const value = modulesFiles(modulePath)
|
|
|
|
modules[moduleName] = value.default
|
|
|
|
return modules
|
|
|
|
}, {})
|
|
|
|
|
2017-04-18 07:09:13 +00:00
|
|
|
const store = new Vuex.Store({
|
2019-04-04 06:37:01 +00:00
|
|
|
modules,
|
2017-04-18 07:09:13 +00:00
|
|
|
getters
|
2017-08-22 07:43:34 +00:00
|
|
|
})
|
2017-04-18 07:09:13 +00:00
|
|
|
|
|
|
|
export default store
|