Pārlūkot izejas kodu

feat(optimization): 添加分包优化和异步组件支持,更新相关配置

feige996 7 mēneši atpakaļ
vecāks
revīzija
e1414ee07f
3 mainītis faili ar 17 papildinājumiem un 13 dzēšanām
  1. 3 0
      manifest.config.ts
  2. 2 0
      tsconfig.json
  3. 12 13
      vite.config.ts

+ 3 - 0
manifest.config.ts

@@ -135,6 +135,9 @@ export default defineManifestConfig({
   'mp-alipay': {
     usingComponents: true,
     styleIsolation: 'shared',
+    optimization: {
+      subPackages: true,
+    },
   },
   'mp-baidu': {
     usingComponents: true,

+ 2 - 0
tsconfig.json

@@ -17,6 +17,8 @@
       "miniprogram-api-typings",
       "wot-design-uni/global.d.ts",
       "z-paging/types",
+      "./src/types/async-component.d.ts",
+      "./src/types/async-import.d.ts",
       "./src/typings.d.ts"
     ],
     "allowJs": true,

+ 12 - 13
vite.config.ts

@@ -70,6 +70,18 @@ export default defineConfig(({ command, mode }) => {
       UniLayouts(),
       UniPlatform(),
       UniManifest(),
+      // Optimization 插件需要 page.json 文件,故应在 UniPages 插件之后执行
+      Optimization({
+        enable: {
+          'optimization': true,
+          'async-import': true,
+          'async-component': true,
+        },
+        dts: {
+          base: 'src/types',
+        },
+        logger: true,
+      }),
       // UniXXX 需要在 Uni 之前引入
       {
         // 临时解决 dcloudio 官方的 @dcloudio/uni-mp-compiler 出现的编译 BUG
@@ -90,19 +102,6 @@ export default defineConfig(({ command, mode }) => {
         dirs: ['src/hooks'], // 自动导入 hooks
         vueTemplate: true, // default false
       }),
-      // Optimization 插件需要 page.json 文件,故应在 UniPages 插件之后执行
-      Optimization({
-        enable: {
-          'optimization': true,
-          'async-import': true,
-          'async-component': true,
-        },
-        dts: {
-          base: 'src/types',
-        },
-        logger: false,
-      }),
-
       ViteRestart({
         // 通过这个插件,在修改vite.config.js文件则不需要重新运行也生效配置
         restart: ['vite.config.js'],