版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { SourceMapInput, EmittedAsset, AcornNode, Plugin, PluginContextMeta } from 'rollup';
  2. export { Plugin as RollupPlugin } from 'rollup';
  3. import { Compiler, WebpackPluginInstance } from 'webpack';
  4. export { Compiler as WebpackCompiler } from 'webpack';
  5. import { Plugin as Plugin$1 } from 'vite';
  6. export { Plugin as VitePlugin } from 'vite';
  7. import { Plugin as Plugin$2, PluginBuild } from 'esbuild';
  8. export { Plugin as EsbuildPlugin } from 'esbuild';
  9. import { Compiler as Compiler$1, RspackPluginInstance } from '@rspack/core';
  10. import VirtualModulesPlugin from 'webpack-virtual-modules';
  11. type Thenable<T> = T | Promise<T>;
  12. interface SourceMapCompact {
  13. file?: string;
  14. mappings: string;
  15. names: string[];
  16. sourceRoot?: string;
  17. sources: string[];
  18. sourcesContent?: (string | null)[];
  19. version: number;
  20. }
  21. type TransformResult = string | {
  22. code: string;
  23. map?: SourceMapInput | SourceMapCompact | null;
  24. } | null | undefined;
  25. interface ExternalIdResult {
  26. id: string;
  27. external?: boolean;
  28. }
  29. interface UnpluginBuildContext {
  30. addWatchFile: (id: string) => void;
  31. emitFile: (emittedFile: EmittedAsset) => void;
  32. getWatchFiles: () => string[];
  33. parse: (input: string, options?: any) => AcornNode;
  34. }
  35. interface UnpluginOptions {
  36. name: string;
  37. enforce?: 'post' | 'pre' | undefined;
  38. buildStart?: (this: UnpluginBuildContext) => Promise<void> | void;
  39. buildEnd?: (this: UnpluginBuildContext) => Promise<void> | void;
  40. transform?: (this: UnpluginBuildContext & UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
  41. load?: (this: UnpluginBuildContext & UnpluginContext, id: string) => Thenable<TransformResult>;
  42. resolveId?: (id: string, importer: string | undefined, options: {
  43. isEntry: boolean;
  44. }) => Thenable<string | ExternalIdResult | null | undefined>;
  45. watchChange?: (this: UnpluginBuildContext, id: string, change: {
  46. event: 'create' | 'update' | 'delete';
  47. }) => void;
  48. writeBundle?: (this: void) => Promise<void> | void;
  49. /**
  50. * Custom predicate function to filter modules to be loaded.
  51. * When omitted, all modules will be included (might have potential perf impact on Webpack).
  52. */
  53. loadInclude?: (id: string) => boolean | null | undefined;
  54. /**
  55. * Custom predicate function to filter modules to be transformed.
  56. * When omitted, all modules will be included (might have potential perf impact on Webpack).
  57. */
  58. transformInclude?: (id: string) => boolean | null | undefined;
  59. rollup?: Partial<Plugin>;
  60. webpack?: (compiler: Compiler) => void;
  61. rspack?: (compiler: Compiler$1) => void;
  62. vite?: Partial<Plugin$1>;
  63. esbuild?: {
  64. onResolveFilter?: RegExp;
  65. onLoadFilter?: RegExp;
  66. setup?: Plugin$2['setup'];
  67. };
  68. }
  69. interface ResolvedUnpluginOptions extends UnpluginOptions {
  70. __vfs?: VirtualModulesPlugin;
  71. __vfsModules?: Set<string>;
  72. __virtualModulePrefix: string;
  73. }
  74. type UnpluginFactory<UserOptions, Nested extends boolean = boolean> = (options: UserOptions, meta: UnpluginContextMeta) => Nested extends true ? Array<UnpluginOptions> : UnpluginOptions;
  75. type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions ? (options?: UserOptions) => Return : (options: UserOptions) => Return;
  76. interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
  77. rollup: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin> : Plugin>;
  78. vite: UnpluginFactoryOutput<UserOptions, Nested extends true ? Array<Plugin$1> : Plugin$1>;
  79. webpack: UnpluginFactoryOutput<UserOptions, WebpackPluginInstance>;
  80. rspack: UnpluginFactoryOutput<UserOptions, RspackPluginInstance>;
  81. esbuild: UnpluginFactoryOutput<UserOptions, Plugin$2>;
  82. raw: UnpluginFactory<UserOptions, Nested>;
  83. }
  84. type UnpluginContextMeta = Partial<PluginContextMeta> & ({
  85. framework: 'rollup' | 'vite';
  86. } | {
  87. framework: 'webpack';
  88. webpack: {
  89. compiler: Compiler;
  90. };
  91. } | {
  92. framework: 'esbuild';
  93. build?: PluginBuild;
  94. /** Set the host plugin name of esbuild when returning multiple plugins */
  95. esbuildHostName?: string;
  96. } | {
  97. framework: 'rspack';
  98. rspack: {
  99. compiler: Compiler$1;
  100. };
  101. });
  102. interface UnpluginContext {
  103. error(message: any): void;
  104. warn(message: any): void;
  105. }
  106. declare module 'webpack' {
  107. interface Compiler {
  108. $unpluginContext: Record<string, ResolvedUnpluginOptions>;
  109. }
  110. }
  111. declare function createUnplugin<UserOptions, Nested extends boolean = boolean>(factory: UnpluginFactory<UserOptions, Nested>): UnpluginInstance<UserOptions, Nested>;
  112. export { ExternalIdResult, ResolvedUnpluginOptions, SourceMapCompact, Thenable, TransformResult, UnpluginBuildContext, UnpluginContext, UnpluginContextMeta, UnpluginFactory, UnpluginFactoryOutput, UnpluginInstance, UnpluginOptions, createUnplugin };