产品库升级,不用再改加载路径了

This commit is contained in:
aixianling
2022-03-09 11:58:28 +08:00
parent 93b1a3a69d
commit 7940cffc3c
5 changed files with 19 additions and 36 deletions

View File

@@ -1,22 +0,0 @@
//引入当前工程所有的应用
const install = function(Vue) {
if (install.installed) return Promise.resolve();
else {
let contexts = require.context('../packages', true, /(\/.+)\/App[^\/]+\.vue$/);
if (contexts) {
contexts.keys().map((e) => {
if (contexts(e).default) {
Vue.component(contexts(e).default.name, contexts(e).default);
}
});
}
}
};
// 判断是否是直接引入文件
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue);
}
export default {
// 导出的对象必须具有 install才能被 Vue.use() 方法安装
install
};

View File

@@ -2,7 +2,6 @@ import Vue from 'vue';
import App from './App.vue';
import ui from 'element-ui';
import router from './router/router';
import apps from './entries';
import axios from './router/axios';
import utils from './utils';
import vcUI from 'dvcp-ui';
@@ -14,7 +13,6 @@ import dataV from '@jiaminghi/data-view';
Vue.use(dataV);
Vue.use(apps);
Vue.use(ui);
Vue.use(vcUI);
Vue.use(dvUI);
@@ -25,7 +23,7 @@ Vue.prototype.formatContent = (val) => val.replace(/(\r\n)|(\n)/g, '<br>');
Object.keys(utils).map((e) => (Vue.prototype[e] = utils[e]));
utils.$store.init(store);
new Vue({
router,
store,
render: (h) => h(App)
router,
store,
render: (h) => h(App)
}).$mount('#app');

View File

@@ -21,8 +21,9 @@ export default {
let {name, label} = files(path).default,
addApp = {
name, label: label || name,
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
entry: 'appEntry'
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/packages$1'),
entry: 'appEntry',
module: files(path).default
}
//命名规范入口文件必须以App开头
store.commit("addApp", addApp)
@@ -34,8 +35,9 @@ export default {
let {name, label} = cores(path).default,
addApp = {
name, label: label || name,
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
entry: 'appEntry'
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/core$1'),
entry: 'appEntry',
module: cores(path).default
}
//命名规范入口文件必须以App开头
store.commit("addApp", addApp)
@@ -46,9 +48,10 @@ export default {
if (project(path).default) {
let {name, label} = project(path).default,
addApp = {
name, label: label || name,
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '$1'),
entry: 'appEntry'
name: [path.replace(/\.\/([^\/]+)\/.*/, '$1'), name].join("_"), label: label || name,
path: path.replace(/\.(\/.+\/App.+)\.vue$/, '/project$1'),
entry: 'appEntry',
module: project(path).default
}
//命名规范入口文件必须以App开头
store.commit("addApp", addApp)

View File

@@ -7,12 +7,16 @@
<script>
import {mapState} from "vuex";
export default {
name: "appEntry",
label: "应用库-应用",
computed: {
...mapState(['apps']),
app() {
return this.$route.name
let app = this.apps.find(e => e.name == this.$route.name)
return app ? app.module : ""
}
}
}

View File

@@ -6,7 +6,6 @@
"main": "lib/cw-webapps.common.js",
"scripts": {
"serve": "vue-cli-service serve",
"serve:oms": "npx cross-env NODE_ENV=oms vue-cli-service serve",
"build": "vue-cli-service build",
"lib": "vue-cli-service build --no-clean --target lib --dest lib packages/index.js&&npm unpublish --force&&npm publish",
"lib:core": "vue-cli-service build --target lib --dest core/dist core/index.js --name vc-app-core&&npm unpublish --force&&npm publish",
@@ -55,6 +54,7 @@
"image-webpack-loader": "^6.0.0",
"inquirer": "^6.5.2",
"node-sass": "npm:sass@^1.43.4",
"readline": "^1.3.0",
"sass-loader": "^7.1.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"v-viewer": "^1.6.4",