styleImport.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Introduces component library styles on demand.
  3. * https://github.com/anncwb/vite-plugin-style-import
  4. */
  5. import styleImport from 'vite-plugin-style-import';
  6. export function configStyleImportPlugin(isBuild: boolean) {
  7. if (!isBuild) {
  8. return [];
  9. }
  10. const styleImportPlugin = styleImport({
  11. libs: [
  12. {
  13. libraryName: 'ant-design-vue',
  14. esModule: true,
  15. resolveStyle: (name) => {
  16. // 这里是“子组件”列表,无需额外引入样式文件
  17. const ignoreList = [
  18. 'typography-text',
  19. 'typography-title',
  20. 'typography-paragraph',
  21. 'typography-link',
  22. 'anchor-link',
  23. 'sub-menu',
  24. 'menu-item',
  25. 'menu-item-group',
  26. 'dropdown-button',
  27. 'breadcrumb-item',
  28. 'breadcrumb-separator',
  29. 'input-password',
  30. 'input-search',
  31. 'input-group',
  32. 'form-item',
  33. 'radio-group',
  34. 'checkbox-group',
  35. 'layout-sider',
  36. 'layout-content',
  37. 'layout-footer',
  38. 'layout-header',
  39. 'step',
  40. 'select-option',
  41. 'select-opt-group',
  42. 'card-grid',
  43. 'card-meta',
  44. 'collapse-panel',
  45. 'descriptions-item',
  46. 'list-item',
  47. 'list-item-meta',
  48. 'table-column',
  49. 'table-column-group',
  50. 'tab-pane',
  51. 'tab-content',
  52. 'timeline-item',
  53. 'tree-node',
  54. 'skeleton-input',
  55. 'skeleton-avatar',
  56. 'skeleton-title',
  57. 'skeleton-paragraph',
  58. 'skeleton-image',
  59. 'skeleton-button',
  60. ];
  61. return ignoreList.includes(name) ? '' : `ant-design-vue/es/${name}/style/index`;
  62. },
  63. },
  64. ],
  65. });
  66. return styleImportPlugin;
  67. }