af58ae347f1010210c01431bd2fd319a67bc364b.svn-base 712 B

12345678910111213141516171819202122232425
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import getters from './getters'
  4. Vue.use(Vuex)
  5. // https://webpack.js.org/guides/dependency-management/#requirecontext
  6. const modulesFiles = require.context('./modules', true, /\.js$/)
  7. // you do not need `import app from './modules/app'`
  8. // it will auto require all vuex module from modules file
  9. const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  10. // set './app.js' => 'app'
  11. const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  12. const value = modulesFiles(modulePath)
  13. modules[moduleName] = value.default
  14. return modules
  15. }, {})
  16. const store = new Vuex.Store({
  17. modules,
  18. getters
  19. })
  20. export default store