Browse Source

fix: demo refresh bug

richard1015 4 years ago
parent
commit
1f94029361
5 changed files with 7 additions and 32 deletions
  1. 2 1
      package.json
  2. 0 23
      scripts/gen-nutui-main.ts
  3. 4 7
      src/nutui.ts
  4. 1 1
      vite.config.ts
  5. 0 0
      vue.config.old.js

+ 2 - 1
package.json

@@ -52,6 +52,7 @@
   "devDependencies": {
     "@commitlint/cli": "^10.0.0",
     "@commitlint/config-conventional": "^10.0.0",
+    "@types/node": "^14.14.31",
     "@vitejs/plugin-vue": "^1.1.4",
     "@vue/compiler-sfc": "^3.0.5",
     "@vue/eslint-config-prettier": "^6.0.0",
@@ -103,4 +104,4 @@
     "type": "git",
     "url": "https://github.com/jdf2e/nutui.git"
   }
-}
+}

+ 0 - 23
scripts/gen-nutui-main.ts

@@ -1,23 +0,0 @@
-/**
- * 生成入口文件
- */
-export class Gen {
-  constructor() {
-    this.init();
-  }
-
-  init() {
-    const template = `
-        import { App } from 'vue';
-        export default {
-            install(app: App<Element>): void {
-                const files = require.context('@/packages', true, /index\.vue$/);
-                files.keys().forEach(component => {
-                const componentEntity = files(component).default;
-                app.component(componentEntity.name, componentEntity);
-                });
-            }
-        };
-        `;
-  }
-}

+ 4 - 7
src/nutui.ts

@@ -1,6 +1,5 @@
-import { App } from 'vue';
 export default {
-  async install(app: App<Element>): Promise<void> {
+  async install(app: any): Promise<void> {
     /** webpack */
     // const files = require.context('@/packages', true, /index\.vue$/);
     // files.keys().forEach(component => {
@@ -9,11 +8,9 @@ export default {
     // });
 
     /** vite */
-    const modulesPage = import.meta.glob('/src/packages/**/index.vue');
-    for (const path in modulesPage) {
-      let name = (/packages\/(.*)\/index.vue/.exec(path) as any[])[1];
-      let res: any = await modulesPage[path]();
-      const componentEntity = res?.default;
+    const modules = import.meta.globEager('/src/packages/**/index.vue');
+    for (const key in modules) {
+      const componentEntity = modules[key]?.default;
       app.component(componentEntity.name, componentEntity);
     }
   }

+ 1 - 1
vite.config.ts

@@ -37,7 +37,7 @@ export default defineConfig({
     },
     lib: {
       entry: 'src/nutui.ts',
-      name: 'MyLib'
+      name: 'nutui'
     }
   }
 });

vue.config.js → vue.config.old.js