优化调整web端内存溢出的问题
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,3 +26,4 @@ yarn-error.log*
|
|||||||
/project/*/index.js
|
/project/*/index.js
|
||||||
/project/*/dist
|
/project/*/dist
|
||||||
/ui/package-lock.json
|
/ui/package-lock.json
|
||||||
|
/examples/modules.json
|
||||||
|
|||||||
33
bin/mods.js
Normal file
33
bin/mods.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
const {chalkTag, findApp, fs, fsExtra} = require("./tools");
|
||||||
|
const compiler = require('vue-template-compiler')
|
||||||
|
const getAppInfo = (file, apps) => {
|
||||||
|
if (/[\\\/](App[A-Z][^\\\/]+)\.vue$/g.test(file)) {
|
||||||
|
const name = file.replace(/.+[\\\/](App[^\\\/]+)\.vue$/, '$1'),
|
||||||
|
source = fs.readFileSync(file).toString(),
|
||||||
|
parsed = compiler.parseComponent(source),
|
||||||
|
script = parsed.script?.content || "",
|
||||||
|
label = script.match(/label:[^,]+/)?.[0]?.replace(/.+["']([^"']+).+/, '$1')
|
||||||
|
const paths = file.split(/[\\\/]/)
|
||||||
|
apps.push({
|
||||||
|
id: file.replace(/\.vue$/, '').replace(/[\\\/]/g, '_'),
|
||||||
|
label: label || name,
|
||||||
|
path: `/${file.replace(/\.vue$/, '').replace(/[\\\/]/g, '/')}`,
|
||||||
|
workspace: paths.at(0),
|
||||||
|
esm: ['.', paths.slice(1)].flat().join("/"),
|
||||||
|
name
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const start = () => {
|
||||||
|
chalkTag.info("开始扫描库工程...")
|
||||||
|
const list = []
|
||||||
|
Promise.all([
|
||||||
|
findApp('packages', app => getAppInfo(app, list)),
|
||||||
|
findApp('project', app => getAppInfo(app, list)),
|
||||||
|
]).then(() => {
|
||||||
|
fsExtra.outputJson('examples/modules.json', {apps: list})
|
||||||
|
chalkTag.done("扫描完毕")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
start()
|
||||||
@@ -2,6 +2,8 @@ import store from "../store";
|
|||||||
import {waiting} from "../utils";
|
import {waiting} from "../utils";
|
||||||
import appEntry from "../views/appEntry";
|
import appEntry from "../views/appEntry";
|
||||||
import router from "./router";
|
import router from "./router";
|
||||||
|
import mods from "../modules"
|
||||||
|
import Vue from "vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
routes: () => store.state.apps,
|
routes: () => store.state.apps,
|
||||||
@@ -9,32 +11,47 @@ export default {
|
|||||||
//约束正则式
|
//约束正则式
|
||||||
store.commit("cleanApps")
|
store.commit("cleanApps")
|
||||||
// 自动化本工程应用
|
// 自动化本工程应用
|
||||||
this.loadApps()
|
waiting.init({innerHTML: '应用加载中..'})
|
||||||
|
this.esm = {
|
||||||
|
packages: require.context('../../packages/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy'),
|
||||||
|
project: require.context('../../project/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy')
|
||||||
|
}
|
||||||
|
const startTime = new Date().getTime()
|
||||||
|
this.loadApps().finally(() => {
|
||||||
|
console.log('模块加载用了%s秒', (new Date().getTime() - startTime) / 1000)
|
||||||
|
waiting.close()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
loadMods() {
|
||||||
|
return Promise.all(mods.apps.map(e => {
|
||||||
|
Vue.component(e.name, this.esm[e.workspace](e.esm))
|
||||||
|
const addApp = {...e, component: appEntry}
|
||||||
|
waiting.setContent(`加载${e.name}...`)
|
||||||
|
//命名规范入口文件必须以App开头
|
||||||
|
return store.commit("addApp", addApp)
|
||||||
|
}))
|
||||||
},
|
},
|
||||||
loadApps() {
|
loadApps() {
|
||||||
//新App的自动化格式
|
//新App的自动化格式
|
||||||
let apps = require.context('../../packages/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy-once'),
|
|
||||||
projects = require.context('../../project/', true, /\.(\/.+)\/App[A-Z][^\/]+\.vue$/, 'lazy-once')
|
|
||||||
const promise = (mods, base) => Promise.all(mods.keys().map(path => mods(path).then(file => {
|
const promise = (mods, base) => Promise.all(mods.keys().map(path => mods(path).then(file => {
|
||||||
if (file.default) {
|
if (file.default) {
|
||||||
let {name, label} = file.default,
|
const {name, label} = file.default
|
||||||
addApp = {
|
const addApp = {
|
||||||
name: [base, path.replace(/\.\/?(vue)?/g, '')?.split("/")].flat().join("_"),
|
name: [base, path.replace(/\.\/?(vue)?/g, '')?.split("/")].flat().join("_"),
|
||||||
label: label || name,
|
label: label || name,
|
||||||
path: `/${base}${path.replace(/\.(\/.+\/App.+)\.vue$/, '$1')}`,
|
path: `/${base}${path.replace(/\.(\/.+\/App.+)\.vue$/, '$1')}`,
|
||||||
component: appEntry,
|
component: appEntry,
|
||||||
module: file.default
|
esm: file.default
|
||||||
}
|
}
|
||||||
waiting.setContent(`加载${name}...`)
|
waiting.setContent(`加载${name}...`)
|
||||||
router.addRoute(addApp)
|
router.addRoute(addApp)
|
||||||
//命名规范入口文件必须以App开头
|
//命名规范入口文件必须以App开头
|
||||||
return store.commit("addApp", addApp)
|
return store.commit("addApp", addApp)
|
||||||
} else return 0
|
} else return 0
|
||||||
})))
|
}).catch(err => console.log(err))))
|
||||||
waiting.init({innerHTML: '应用加载中..'})
|
return Promise.all([
|
||||||
Promise.all([
|
promise(this.esm.packages, "packages"),
|
||||||
promise(apps, "packages"),
|
promise(this.esm.project, "project")
|
||||||
promise(projects, "project")
|
])
|
||||||
]).finally(() => waiting.close())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ instance.interceptors.request.use(config => {
|
|||||||
config.baseURL = "/qxn"
|
config.baseURL = "/qxn"
|
||||||
} else if (/\/xiushan/.test(location.pathname)) {
|
} else if (/\/xiushan/.test(location.pathname)) {
|
||||||
config.baseURL = "/xsjr"
|
config.baseURL = "/xsjr"
|
||||||
} else if (/project\/oms/.test(location.pathname)) {
|
// } else if (/project\/oms/.test(location.pathname)) {
|
||||||
config.baseURL = "/omsapi"
|
// config.baseURL = "/omsapi"
|
||||||
} else if (/#url-/.test(location.hash)) {
|
} else if (/#url-/.test(location.hash)) {
|
||||||
config.baseURL = location.hash.replace(/#url-/, '/')
|
config.baseURL = location.hash.replace(/#url-/, '/')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
import {mapState} from "vuex";
|
import {mapState} from "vuex";
|
||||||
|
import Vue from "vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "appEntry",
|
name: "appEntry",
|
||||||
@@ -15,8 +16,8 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState(['apps']),
|
...mapState(['apps']),
|
||||||
app() {
|
app() {
|
||||||
let app = this.apps.find(e => e.name == this.$route.name)
|
const app = this.apps.find(e => e.name == this.$route.name)
|
||||||
return app ? app.module : ""
|
return app.esm ?? ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ module.exports = {
|
|||||||
.add(path.resolve(__dirname, 'project'))
|
.add(path.resolve(__dirname, 'project'))
|
||||||
.add(path.resolve(__dirname, 'examples'))
|
.add(path.resolve(__dirname, 'examples'))
|
||||||
.add(path.resolve(__dirname, 'ui'))
|
.add(path.resolve(__dirname, 'ui'))
|
||||||
.end()
|
.end().use('babel').loader('babel-loader').tap(options => options);
|
||||||
.use('babel')
|
config.output.chunkFilename('[name].js');
|
||||||
.loader('babel-loader')
|
config.plugins.delete("friendly-errors");
|
||||||
.tap(options => options);
|
config.plugin("limit").use(require("webpack/lib/optimize/LimitChunkCountPlugin"), [{maxChunks: 10}]).tap(options => options)
|
||||||
},
|
},
|
||||||
devServer: {
|
devServer: {
|
||||||
host: '0.0.0.0', //主机地址
|
host: '0.0.0.0', //主机地址
|
||||||
@@ -136,6 +136,6 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
disableHostCheck: true
|
disableHostCheck: true,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user