diff --git a/index.html b/index.html index 1594bcc..e1471f4 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@
Lade, bitte warten...
- + \ No newline at end of file diff --git a/src/baseui.js b/src/lib/baseui.js similarity index 75% rename from src/baseui.js rename to src/lib/baseui.js index c86b73b..3077c7c 100644 --- a/src/baseui.js +++ b/src/lib/baseui.js @@ -4,6 +4,8 @@ import VueRouter from 'vue-router'; import Axios from 'axios'; import JwtDecode from 'jwt-decode'; +import App from 'app.vue'; + import MyForm from 'components/my-form.vue'; import MyInput from 'components/my-input.vue'; import TextareaInput from 'components/textarea-input.vue'; @@ -176,5 +178,55 @@ export default { Vue, Router, Store, - Axios + Axios, + InitApp(config) { // config: {initUrl, views, el} + Axios.get(config.initUrl) + .then(results => { + // set navigation + if (!Array.isArray(results.data.routes)) { + alert('invalid data in init.json, no routes'); + return; + } + + // set ui config in store + Store.commit("setUI", results.data.ui); + + // add routes + let routes = []; + let rIdx = 0; + results.data.routes.forEach(({ name, to, content, data }) => routes.push({ + name: name, + path: to, + meta: { + title: name + }, + component: { + template: '
' + content + '
', + components: config.views, + data: function (data) { + if (typeof data != 'object') { + return () => { return {}; }; + } + return () => { return data; }; + }(data) + } + })); + Router.addRoutes(routes); + Router.beforeEach((to, from, next) => { + document.title = (to.meta && to.meta.title) ? results.data.ui.title + ': ' + to.meta.title : results.data.title; + next(); + }); + + // load app, when init finishs + new Vue({ + el: config.el, + render: h => h(App), + router: Router, + store: Store + }); + }) + .catch(error => { + alert('error loading: ' + error.message); + }); + } }; \ No newline at end of file diff --git a/src/main.js b/src/main.js index c41f896..1a6da1b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,57 +1,10 @@ -import BaseUI from './baseui.js'; -import App from './app.vue'; -// import Views from './views/views.js'; +import BaseUI from './lib/baseui.js'; +import Views from './views/views.js'; -// load views -import(/* webpackChunkName: "views" */ './views/views.js').then(Views => { - // load init - BaseUI.Axios.get('conf/init.json') - .then(results => { - // set navigation - if (!Array.isArray(results.data.routes)) { - alert('invalid data in init.json, no routes'); - return; - } - - // set ui config in store - BaseUI.Store.commit("setUI", results.data.ui); - - // add routes - let routes = []; - let rIdx = 0; - results.data.routes.forEach(({name, to, content, data}) => routes.push({ - name: name, - path: to, - meta: { - title: name - }, - component: { - template: '
' + content + '
', - components: Views.default, - data: function(data) { - if (typeof data != 'object') { - return () => { return {}; }; - } - return () => { return data; }; - }(data) - } - })); - BaseUI.Router.addRoutes(routes); - BaseUI.Router.beforeEach((to, from, next) => { - document.title = (to.meta && to.meta.title) ? results.data.ui.title + ': ' + to.meta.title : results.data.title; - next(); - }); - - // load app, when init finishs - new BaseUI.Vue({ - el: '#vue-app', - render: h => h(App), - router: BaseUI.Router, - store: BaseUI.Store - }); - }) - .catch(error => { - alert('error loading: ' + error.message); - }); +// load init +BaseUI.InitApp({ + el: '#vue-app', + initUrl: 'conf/init.json', + views: Views }); \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 5e5f065..4020c37 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -30,17 +30,25 @@ if (env === 'production') { // Main Settings config module.exports = { - entry: [ - 'intersection-observer', - 'babel-polyfill', - entryPoint - ], + entry: { + lib: [ + 'intersection-observer', + 'babel-polyfill', + './src/lib/baseui.js' + ], + main: [ + 'intersection-observer', + 'babel-polyfill', + entryPoint + ] + }, devtool: 'source-map', output: { path: exportPath, publicPath: 'build/', - filename: '[name].bundle.js', - chunkFilename: '[name].bundle.js' + filename: 'baseui-[name].bundle.js', + library: 'baseUI', + libraryTarget: 'umd' }, module: { loaders: [{