styleImport.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Introduces component library styles on demand.
  3. * 按需引入组件库样式
  4. * https://github.com/anncwb/vite-plugin-style-import
  5. */
  6. import styleImport from 'vite-plugin-style-import'
  7. export default function configStyleImportPlugin() {
  8. const styleImportPlugin = styleImport({
  9. libs: [
  10. {
  11. libraryName: '@arco-design/web-vue',
  12. esModule: true,
  13. resolveStyle: name => {
  14. // The use of this part of the component must depend on the parent, so it can be ignored directly.
  15. // 这部分组件的使用必须依赖父级,所以直接忽略即可。
  16. const ignoreList = [
  17. 'countdown',
  18. 'config-provider',
  19. 'anchor-link',
  20. 'sub-menu',
  21. 'menu-item',
  22. 'menu-item-group',
  23. 'breadcrumb-item',
  24. 'form-item',
  25. 'step',
  26. 'card-grid',
  27. 'card-meta',
  28. 'collapse-panel',
  29. 'collapse-item',
  30. 'descriptions-item',
  31. 'list-item',
  32. 'list-item-meta',
  33. 'table-column',
  34. 'table-column-group',
  35. 'tab-pane',
  36. 'tab-content',
  37. 'timeline-item',
  38. 'tree-node',
  39. 'skeleton-line',
  40. 'skeleton-shape',
  41. 'grid-item',
  42. 'carousel-item',
  43. 'doption',
  44. 'option',
  45. 'optgroup',
  46. 'icon'
  47. // 'iconFont'
  48. ]
  49. // List of components that need to map imported styles
  50. // 需要映射引入样式的组件列表
  51. const replaceList = {
  52. 'typography-text': 'typography',
  53. 'typography-title': 'typography',
  54. 'typography-paragraph': 'typography',
  55. 'typography-link': 'typography',
  56. 'dropdown-button': 'dropdown',
  57. 'input-password': 'input',
  58. 'input-textarea': 'input',
  59. 'input-search': 'input',
  60. 'input-group': 'input',
  61. 'radio-group': 'radio',
  62. 'checkbox-group': 'checkbox',
  63. 'layout-sider': 'layout',
  64. 'layout-content': 'layout',
  65. 'layout-footer': 'layout',
  66. 'layout-header': 'layout',
  67. 'month-picker': 'date-picker',
  68. 'year-picker': 'date-picker',
  69. 'range-picker': 'date-picker',
  70. row: 'grid',
  71. col: 'grid',
  72. icon: 'icon',
  73. 'avatar-group': 'avatar',
  74. 'image-preview': 'image',
  75. 'image-preview-group': 'image'
  76. }
  77. if (ignoreList.includes(name)) return ''
  78. // eslint-disable-next-line no-prototype-builtins
  79. return replaceList.hasOwnProperty(name)
  80. ? `@arco-design/web-vue/es/${replaceList[name]}/style/css.js`
  81. : `@arco-design/web-vue/es/${name}/style/css.js`
  82. // less
  83. // return `@arco-design/web-vue/es/${name}/style/index.js`;
  84. }
  85. }
  86. ]
  87. })
  88. return styleImportPlugin
  89. }