-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dynamic router & store
- Loading branch information
Faizal Andyka
committed
Mar 9, 2021
1 parent
3293de7
commit be101c1
Showing
2 changed files
with
21 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
/** | ||
* TODO: | ||
* dynamically read file inside modules | ||
* using require.context. https://github.com/vitejs/vite/issues/77 | ||
*/ | ||
|
||
import { createStore } from 'vuex' | ||
import globalStores from './stores' | ||
|
||
const domainStoreFiles = import.meta.globEager('../src/modules/**/store.ts') | ||
let domainStores = {} | ||
|
||
for (const path in domainStoreFiles) { | ||
for (const key in domainStoreFiles[path]) { | ||
domainStores[key] = domainStoreFiles[path][key] | ||
} | ||
} | ||
|
||
const store = createStore({ | ||
strict: import.meta.env.VITE_APP_ENV !== 'production', | ||
modules: { ...globalStores } | ||
modules: { | ||
...globalStores, | ||
...domainStores | ||
} | ||
}) | ||
|
||
export default store | ||
export default store |