index.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Plugin } from 'vite';
  2. declare type RegOptions = string | RegExp | (string | RegExp)[] | null | undefined;
  3. interface Lib {
  4. importTest?: RegExp;
  5. /**
  6. * Dependent library name
  7. */
  8. libraryName: string;
  9. /**
  10. * When the imported style file does not end with .css, it needs to be turned on
  11. * @default: false
  12. */
  13. esModule?: boolean;
  14. /**
  15. * Custom imported component style conversion
  16. */
  17. resolveStyle?: (name: string) => string;
  18. /**
  19. * There may be some component libraries that are not very standardized.
  20. * You can turn on this to ignore to determine whether the file exists. Prevent errors when importing non-existent css files.
  21. * Performance may be slightly reduced after it is turned on, but the impact is not significant
  22. * @default: false
  23. */
  24. ensureStyleFile?: boolean;
  25. /**
  26. * Custom component file conversion
  27. * Turning on the environment does not work
  28. */
  29. resolveComponent?: (name: string) => string;
  30. /**
  31. * https://github.com/anncwb/vite-plugin-style-import/issues/12
  32. * `import ${libName} from 'xxxx';`
  33. * Used for custom import name
  34. */
  35. transformComponentImportName?: (name: string) => string;
  36. /**
  37. * Customize imported component file name style conversion
  38. * @default: paramCase
  39. */
  40. libraryNameChangeCase?: LibraryNameChangeCase;
  41. /**
  42. * Whether to introduce base style
  43. */
  44. base?: string;
  45. }
  46. interface VitePluginOptions {
  47. include?: RegOptions;
  48. exclude?: RegOptions;
  49. /**
  50. * @default process.cwd()
  51. * @deprecated 1.2.0 is obsolete
  52. */
  53. root?: string;
  54. libs?: Lib[];
  55. resolves?: Lib[];
  56. }
  57. interface Source {
  58. opts: {
  59. libs: Lib[];
  60. cacheDir: string;
  61. };
  62. }
  63. declare type LibraryNameChangeCase = ChangeCaseType | ((name: string) => string);
  64. declare type ChangeCaseType = 'camelCase' | 'capitalCase' | 'constantCase' | 'dotCase' | 'headerCase' | 'noCase' | 'paramCase' | 'pascalCase' | 'pathCase' | 'sentenceCase' | 'snakeCase';
  65. declare function AntdResolve(): Lib;
  66. declare function AndDesignVueResolve(): Lib;
  67. declare function ElementPlusResolve(): Lib;
  68. declare function VantResolve(): Lib;
  69. declare function NutuiResolve(): Lib;
  70. declare function VxeTableResolve(): Lib;
  71. declare const _default: (options: VitePluginOptions) => Plugin;
  72. declare function transformImportVar(importStr: string): readonly string[];
  73. declare function getChangeCaseFileName(importedName: string, libraryNameChangeCase: LibraryNameChangeCase): string;
  74. export { AndDesignVueResolve, AntdResolve, ChangeCaseType, ElementPlusResolve, Lib, LibraryNameChangeCase, NutuiResolve, RegOptions, Source, VantResolve, VitePluginOptions, VxeTableResolve, _default as default, getChangeCaseFileName, transformImportVar };