Blame view

build/vite/plugin/styleImport.ts 2.48 KB
vben authored
1
2
3
4
/**
 *  Introduces component library styles on demand.
 * https://github.com/anncwb/vite-plugin-style-import
 */
vben authored
5
import { createStyleImportPlugin } from 'vite-plugin-style-import';
vben authored
6
7
8
9
10
export function configStyleImportPlugin(_isBuild: boolean) {
  // if (!isBuild) {
  //   return [];
  // }
vben authored
11
  const styleImportPlugin = createStyleImportPlugin({
vben authored
12
13
14
    libs: [
      {
        libraryName: 'ant-design-vue',
vben authored
15
        esModule: true,
vben authored
16
        resolveStyle: (name) => {
17
          // 这里是无需额外引入样式文件的“子组件”列表
18
19
20
21
          const ignoreList = [
            'anchor-link',
            'sub-menu',
            'menu-item',
22
            'menu-divider',
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
            'menu-item-group',
            'breadcrumb-item',
            'breadcrumb-separator',
            'form-item',
            'step',
            'select-option',
            'select-opt-group',
            'card-grid',
            'card-meta',
            'collapse-panel',
            'descriptions-item',
            'list-item',
            'list-item-meta',
            'table-column',
            'table-column-group',
            'tab-pane',
            'tab-content',
            'timeline-item',
            'tree-node',
            'skeleton-input',
            'skeleton-avatar',
            'skeleton-title',
            'skeleton-paragraph',
            'skeleton-image',
            'skeleton-button',
          ];
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
          // 这里是需要额外引入样式的子组件列表
          // 单独引入子组件时需引入组件样式,否则会在打包后导致子组件样式丢失
          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`;
vben authored
74
75
76
77
        },
      },
    ],
  });
江麻妞 authored
78
  return styleImportPlugin;
vben authored
79
}