1- import { Plugin , UserConfig } from 'vite' ;
1+ import { Plugin } from 'vite' ;
22
33declare const optimizer : VitePluginOptimizer ;
44export default optimizer ;
@@ -10,20 +10,24 @@ export interface OptimizerArgs {
1010
1111export interface ResultDescription {
1212 /**
13- * this option is designed to fully support `alias`
14- * this is useful if users want to customize alias
15- * ```js
13+ * This is consistent with the `alias` behavior.
14+ *
15+ * e.g.
16+ * `import fs from 'fs'`
17+ * or
18+ * `import fs from 'node:fs'`
19+ *
20+ * @example
1621 * {
17- * // e.g. 👉 `/^(node:)?fs$/` from user customization
22+ * // This means that both 'fs' and 'node:fs' are supported.
1823 * find: /^(node:)?fs$/,
1924 * replacement: '/project/node_modules/.vite-plugin-optimizer/fs.js',
2025 * }
21- * ```
2226 */
2327 alias ?: {
2428 find : string | RegExp ;
2529 /**
26- * If not specified, the path of the generated file is used .
30+ * If not explicitly specified, will use the path to the generated file as the default .
2731 */
2832 replacement ?: string ;
2933 } ;
@@ -34,19 +38,15 @@ export interface Entries {
3438 [ moduleId : string ] :
3539 | string
3640 | ResultDescription
37- | ( ( args : OptimizerArgs ) => string | ResultDescription | Promise < string | ResultDescription | void > | void )
38- | void ;
41+ | ( ( args : OptimizerArgs ) => string | ResultDescription | Promise < string | ResultDescription | void > | void ) ;
3942}
4043
4144export interface OptimizerOptions {
4245 /**
4346 * @default ".vite-plugin-optimizer"
4447 */
4548 dir ?: string ;
46- /**
47- * @default ".js"
48- */
49- ext ?: string ;
49+ resolveId ?: ( ( id : string ) => string | Promise < string | void > | void ) ;
5050}
5151
5252export interface VitePluginOptimizer {
@@ -58,20 +58,9 @@ export interface VitePluginOptimizer {
5858export type GenerateRecord = {
5959 alias ?: ResultDescription [ 'alias' ] ;
6060 module : string ;
61- // absolute path of file
62- filepath : string ;
61+ // Absolute path of file
62+ filename : string ;
6363} ;
6464export interface GenerateModule {
65- ( dir : string , entries : Entries , ext : string ) : Promise < GenerateRecord [ ] > ;
66- }
67-
68- export interface RegisterAlias {
69- (
70- config : UserConfig ,
71- records : GenerateRecord [ ] ,
72- ) : void ;
73- }
74-
75- export interface RegisterOptimizeDepsExclude {
76- ( config : UserConfig , exclude : string [ ] ) : void ;
65+ ( ...args : Parameters < VitePluginOptimizer > ) : Promise < GenerateRecord [ ] > ;
7766}
0 commit comments