@xilonglab/vue-main 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/packages/index.js +14 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xilonglab/vue-main",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "xilong vue main",
5
5
  "main": "packages/index.js",
6
6
  "scripts": {
package/packages/index.js CHANGED
@@ -1,37 +1,22 @@
1
- // 按需懒加载,避免预构建阶段丢失信息
2
- const modules = import.meta.glob('./**/*.vue');
1
+ const components = import.meta.glob('./**/*.vue', { eager: true });
3
2
 
4
- function getComponentName(path, comp) {
5
- if (comp && comp.name) return comp.name;
6
- // 从路径提取文件名作为组件名(去掉扩展名)
7
- return path.split('/').pop().replace(/\.\w+$/, '');
8
- }
9
-
10
- const install = async (app) => {
11
- for (const path in modules) {
12
- const mod = await modules[path](); // 浏览器端动态导入
13
- const comp = mod.default;
14
- const name = getComponentName(path, comp);
15
- if (!name) {
16
- console.warn(`组件注册失败: ${path} 缺少 name`);
17
- continue;
18
- }
19
- app.component(name, comp);
20
- }
3
+ const install = (app) => {
4
+ Object.values(components).forEach((component) => {
5
+ app.component(component.default.name, component.default);
6
+ });
21
7
  };
22
8
 
23
- // 保持原有的单个组件导出方式
24
- let componentsJson = {};
25
- for (const path in modules) {
26
- componentsJson[getComponentName(path)] = async function installComponent(app) {
27
- const mod = await modules[path]();
28
- const comp = mod.default;
29
- const name = getComponentName(path, comp);
30
- app.component(name, comp);
31
- };
9
+ let componentsJson = {}
10
+ for (const key in components) {
11
+ const component = components[key].default
12
+ const componentName = component.name
13
+ component.install = function (app) {
14
+ app.component(componentName, component)
15
+ }
16
+ componentsJson[componentName] = component
32
17
  }
33
18
 
34
19
  export default {
35
20
  install,
36
21
  ...componentsJson
37
- };
22
+ }