Skip to content

Commit

Permalink
feat(store): import store module automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed Mar 7, 2020
1 parent 4caa4c2 commit b1a38bc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/store/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import history from './history'
import { Module } from 'vuex'
import { RootState } from '..'

export default {
history
}
const requireStoreModule = require.context(
'.',
false,
/^\.\/(?!index)\w+\.(t|j)s/ // match all ts file without index.ts
)

export default requireStoreModule.keys().reduce((map, current) => {
const [, moduleName] = /\.\/([\w-]+)\.ts/.exec(current) || []
if (!map[moduleName]) {
map[moduleName] = requireStoreModule(current).default
}
return map
}, {} as Record<string, Module<object, RootState>>)

0 comments on commit b1a38bc

Please sign in to comment.