Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(config): add store config param to vue-app #95

Merged
merged 4 commits into from
Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/config/__tests__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Object {
"plugins": Array [],
"progressbar": true,
"router": Object {},
"store": Object {},
"webpack": Object {
"base": false,
"client": false,
Expand Down
3 changes: 2 additions & 1 deletion packages/config/lib/configs/vue-app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default () => ({
router: {}
router: {},
store: {}
});
3 changes: 2 additions & 1 deletion packages/renderer/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default class Renderer {
progressbar: this.globalConfig.progressbar,
i18n: this.globalConfig.i18n,
csrf: this.globalConfig.csrf,
router: this.globalConfig.router
router: this.globalConfig.router,
store: this.globalConfig.store
}
});

Expand Down
18 changes: 14 additions & 4 deletions packages/vue-app/lib/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import forEach from 'lodash/forEach';
import { ExportVuexStore } from '@averjs/vuex-decorators';
import createPersistedState from 'vuex-persistedstate';
import * as Cookies from 'js-cookie';
import merge from 'lodash/merge'

Vue.use(Vuex);

Expand Down Expand Up @@ -44,10 +45,19 @@ export function createStore(ssrContext) {
);
}

const store = new Vuex.Store({
modules,
plugins
});
let defaultConfig = { modules, plugins };
<% if (typeof config.store === 'object') print('defaultConfig = merge(defaultConfig, JSON.parse(\''+JSON.stringify(config.store)+'\'))'); %>

const mixinContext = require.context('@/', false, /^\.\/store\.js$/i);
for (const r of mixinContext.keys()) {
const mixin = mixinContext(r).default;
if (typeof mixin !== 'undefined') {
const mixinConfig = mixin(defaultConfig);
defaultConfig = merge(defaultConfig, mixinConfig);
}
}

const store = new Vuex.Store(defaultConfig);

if (module.hot) {
files.keys().map(path => files(path));
Expand Down