Browse Source

fix: direct import for antdv subcomponents supported(8b00112) (#1322)

* fix: direct import for antdv subcomponents supported

修复commit<8b00112>使用直接过滤部分antdv子组件的方式,导致build后刷新页面子组件样式会丢失的问题。

* Update styleImport.ts

* Update styleImport.ts
madlight-du 3 years ago
parent
commit
d6cdff97b6
1 changed files with 26 additions and 16 deletions
  1. 26 16
      build/vite/plugin/styleImport.ts

+ 26 - 16
build/vite/plugin/styleImport.ts

@@ -14,29 +14,15 @@ export function configStyleImportPlugin(isBuild: boolean) {
         libraryName: 'ant-design-vue',
         esModule: true,
         resolveStyle: (name) => {
-          // 这里是“子组件”列表,无需额外引入样式文件
+          // 这里是无需额外引入样式文件的“子组件”列表
           const ignoreList = [
-            'typography-text',
-            'typography-title',
-            'typography-paragraph',
-            'typography-link',
             'anchor-link',
             'sub-menu',
             'menu-item',
             'menu-item-group',
-            'dropdown-button',
             'breadcrumb-item',
             'breadcrumb-separator',
-            'input-password',
-            'input-search',
-            'input-group',
             'form-item',
-            'radio-group',
-            'checkbox-group',
-            'layout-sider',
-            'layout-content',
-            'layout-footer',
-            'layout-header',
             'step',
             'select-option',
             'select-opt-group',
@@ -59,7 +45,31 @@ export function configStyleImportPlugin(isBuild: boolean) {
             'skeleton-image',
             'skeleton-button',
           ];
-          return ignoreList.includes(name) ? '' : `ant-design-vue/es/${name}/style/index`;
+          // 这里是需要额外引入样式的子组件列表
+          // 单独引入子组件时需引入组件样式,否则会在打包后导致子组件样式丢失
+          const replaceList = {
+            'typography-text': 'typography',
+            'typography-title': 'typography',
+            'typography-paragraph': 'typography',
+            'typography-link': 'typography',
+            'dropdown-button': 'dropdown',
+            'input-password': 'input',
+            'input-search': 'input',
+            'input-group': 'input',
+            'radio-group': 'radio',
+            'checkbox-group': 'checkbox',
+            'layout-sider': 'layout',
+            'layout-content': 'layout',
+            'layout-footer': 'layout',
+            'layout-header': 'layout',
+            'month-picker': 'date-picker',
+          };
+
+          return ignoreList.includes(name)
+            ? ''
+            : replaceList.hasOwnProperty(name)
+            ? `ant-design-vue/es/${replaceList[name]}/style/index`
+            : `ant-design-vue/es/${name}/style/index`;
         },
       },
     ],