mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-23 22:36:39 +08:00
前端和后端源码,合并到一个git仓库中,方便用户下载,避免前后端不匹配的问题
This commit is contained in:
47
jeecgboot-vue3/src/utils/monorepo/registerPackages.ts
Normal file
47
jeecgboot-vue3/src/utils/monorepo/registerPackages.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import type { App } from 'vue';
|
||||
import { warn } from '/@/utils/log';
|
||||
import { registerDynamicRouter } from '/@/utils/monorepo/dynamicRouter';
|
||||
// 引入模块
|
||||
import PACKAGE_TEST_JEECG_ONLINE from '@jeecg/online';
|
||||
|
||||
export function registerPackages(app: App) {
|
||||
use(app, PACKAGE_TEST_JEECG_ONLINE);
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
const installOptions = {
|
||||
baseImport,
|
||||
};
|
||||
|
||||
/** 注册模块 */
|
||||
function use(app: App, pkg) {
|
||||
app.use(pkg, installOptions);
|
||||
registerDynamicRouter(pkg.getViews);
|
||||
}
|
||||
|
||||
// 模块里可使用的import
|
||||
const importGlobs = [import.meta.glob('../../utils/**/*.{ts,js,tsx}'), import.meta.glob('../../hooks/**/*.{ts,js,tsx}')];
|
||||
|
||||
/**
|
||||
* 基础项目导包
|
||||
* 目前支持导入如下
|
||||
* /@/utils/**
|
||||
* /@/hooks/**
|
||||
*
|
||||
* @param path 文件路径,ts无需输入后缀名。如:/@/utils/common/compUtils
|
||||
*/
|
||||
async function baseImport(path: string) {
|
||||
if (path) {
|
||||
// 将 /@/ 替换成 ../../
|
||||
path = path.replace(/^\/@\//, '../../');
|
||||
for (const glob of importGlobs) {
|
||||
for (const key of Object.keys(glob)) {
|
||||
if (path === key || `${path}.ts` === key || `${path}.tsx` === key) {
|
||||
return glob[key]();
|
||||
}
|
||||
}
|
||||
}
|
||||
warn(`引入失败:${path} 不存在`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user