Skip to content

Commit

Permalink
feat: 优化加载
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft authored and jianbing.chen committed Dec 18, 2024
1 parent 3792e66 commit 25f6980
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/editor/src/packages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { lazy } from 'react';
import components from '../config/components';
import './index.less';

const componentMap: { [key: string]: any } = {};

// 动态导入并注册组件
const registerComponent = async (dir: string, path: string) => {
componentMap[path] = lazy(() => import(`./${dir}/${path}/${path}`));
componentMap[path + 'Config'] = () => import(`./${dir}/${path}/Schema`);
};
for (const { type, data = [] } of components) {
if (data?.length > 0) {
for (const { type: path } of data) {
registerComponent(type, path);
}
} else {
registerComponent('.', type);
/**
* 动态加载组件和Schema配置
*/
const modules: { [key: string]: () => Promise<any> } = import.meta.glob('./[a-zA-Z]+/**');

for (const path in modules) {
const [type, name] = path.split('/').slice(-2);
if (type === 'MarsRender') continue;
if (name.indexOf('Schema') > -1) {
componentMap[type + 'Config'] = modules[path];
}
if (type === name.split('.')?.[0]) {
componentMap[type] = lazy(modules[path]);
}
}

Expand Down

0 comments on commit 25f6980

Please sign in to comment.