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
|
2019-05-20 03:10:30 +00:00
|
|
|
const modulesFiles = require.context('./modules', true, /\.js$/)
|
2019-04-04 06:37:01 +00:00
|
|
|
|
|
|
|
// 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
|