|
1 | 1 | declare module 'vite-plugin-optimizer' { |
2 | | - function optimizer(entries: Entries, options?: OptimizerOptions): import('vite').Plugin; |
3 | | - // https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html#default-exports |
4 | | - export = optimizer; |
5 | | -} |
6 | | - |
7 | | -export interface OptimizerArgs { |
8 | | - /** Generated file cache directory */ |
9 | | - dir: string; |
10 | | -} |
| 2 | + export interface OptimizerArgs { |
| 3 | + /** Generated file cache directory */ |
| 4 | + dir: string; |
| 5 | + } |
11 | 6 |
|
12 | | -export interface ResultDescription { |
13 | | - /** |
14 | | - * This is consistent with the `alias` behavior. |
15 | | - * |
16 | | - * e.g. |
17 | | - * `import fs from 'fs'` |
18 | | - * or |
19 | | - * `import fs from 'node:fs'` |
20 | | - * |
21 | | - * @example |
22 | | - * { |
23 | | - * // This means that both 'fs' and 'node:fs' are supported. |
24 | | - * find: /^(node:)?fs$/, |
25 | | - * replacement: '/project/node_modules/.vite-plugin-optimizer/fs.js', |
26 | | - * } |
27 | | - */ |
28 | | - alias?: { |
29 | | - find: string | RegExp; |
| 7 | + export interface ResultDescription { |
30 | 8 | /** |
31 | | - * If not explicitly specified, will use the path to the generated file as the default. |
| 9 | + * This is consistent with the `alias` behavior. |
| 10 | + * |
| 11 | + * e.g. |
| 12 | + * `import fs from 'fs'` |
| 13 | + * or |
| 14 | + * `import fs from 'node:fs'` |
| 15 | + * |
| 16 | + * @example |
| 17 | + * { |
| 18 | + * // This means that both 'fs' and 'node:fs' are supported. |
| 19 | + * find: /^(node:)?fs$/, |
| 20 | + * replacement: '/project/node_modules/.vite-plugin-optimizer/fs.js', |
| 21 | + * } |
32 | 22 | */ |
33 | | - replacement?: string; |
34 | | - }; |
35 | | - code?: string; |
36 | | -} |
| 23 | + alias?: { |
| 24 | + find: string | RegExp; |
| 25 | + /** |
| 26 | + * If not explicitly specified, will use the path to the generated file as the default. |
| 27 | + */ |
| 28 | + replacement?: string; |
| 29 | + }; |
| 30 | + code?: string; |
| 31 | + } |
37 | 32 |
|
38 | | -export interface Entries { |
39 | | - [moduleId: string]: |
40 | | - | string |
41 | | - | ResultDescription |
42 | | - | ((args: OptimizerArgs) => string | ResultDescription | Promise<string | ResultDescription | void> | void); |
43 | | -} |
| 33 | + export interface Entries { |
| 34 | + [moduleId: string]: |
| 35 | + | string |
| 36 | + | ResultDescription |
| 37 | + | ((args: OptimizerArgs) => string | ResultDescription | Promise<string | ResultDescription | void> | void); |
| 38 | + } |
44 | 39 |
|
45 | | -export interface OptimizerOptions { |
46 | | - /** |
47 | | - * @default ".vite-plugin-optimizer" |
48 | | - */ |
49 | | - dir?: string; |
50 | | - resolveId?: ((id: string) => string | Promise<string | void> | void); |
51 | | -} |
| 40 | + export interface OptimizerOptions { |
| 41 | + /** |
| 42 | + * @default ".vite-plugin-optimizer" |
| 43 | + */ |
| 44 | + dir?: string; |
| 45 | + resolveId?: ((id: string) => string | Promise<string | void> | void); |
| 46 | + } |
52 | 47 |
|
53 | | -// --------- utils --------- |
| 48 | + // --------- utils --------- |
| 49 | + |
| 50 | + export type GenerateRecord = { |
| 51 | + alias?: ResultDescription['alias']; |
| 52 | + module: string; |
| 53 | + // Absolute path of file |
| 54 | + filename: string; |
| 55 | + }; |
54 | 56 |
|
55 | | -export type GenerateRecord = { |
56 | | - alias?: ResultDescription['alias']; |
57 | | - module: string; |
58 | | - // Absolute path of file |
59 | | - filename: string; |
60 | | -}; |
| 57 | + export interface GenerateModule { |
| 58 | + (entries: Entries, options?: OptimizerOptions): Promise<GenerateRecord[]>; |
| 59 | + } |
61 | 60 |
|
62 | | -export interface GenerateModule { |
63 | | - (entries: Entries, options?: OptimizerOptions): Promise<GenerateRecord[]>; |
| 61 | + const optimizer: ((entries: Entries, options?: OptimizerOptions) => import('vite').Plugin); |
| 62 | + export default optimizer; |
64 | 63 | } |
0 commit comments