vite-plugin-dts 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,408 +1,408 @@
1
- <h1 align="center">vite-plugin-dts</h1>
2
-
3
- <p align="center">
4
- A Vite plugin that generates declaration files (<code>*.d.ts</code>) from <code>.ts(x)</code> or <code>.vue</code> source files when using Vite in <a href="https://vitejs.dev/guide/build.html#library-mode">library mode</a>.
5
- </p>
6
-
7
- <p align="center">
8
- <a href="https://www.npmjs.com/package/vite-plugin-dts">
9
- <img src="https://img.shields.io/npm/v/vite-plugin-dts?color=orange&label=" alt="version" />
10
- </a>
11
- <a href="https://github.com/qmhc/vite-plugin-dts/blob/main/LICENSE">
12
- <img src="https://img.shields.io/npm/l/vite-plugin-dts" alt="license" />
13
- </a>
14
- </p>
15
-
16
- **English** | [中文](./README.zh-CN.md)
17
-
18
- ## Install
19
-
20
- ```sh
21
- pnpm i vite-plugin-dts -D
22
- ```
23
-
24
- ## Usage
25
-
26
- In `vite.config.ts`:
27
-
28
- ```ts
29
- import { resolve } from 'path'
30
- import { defineConfig } from 'vite'
31
- import dts from 'vite-plugin-dts'
32
-
33
- export default defineConfig({
34
- build: {
35
- lib: {
36
- entry: resolve(__dirname, 'src/index.ts'),
37
- name: 'MyLib',
38
- formats: ['es'],
39
- fileName: 'my-lib'
40
- }
41
- },
42
- plugins: [dts()]
43
- })
44
- ```
45
-
46
- By default, the generated declaration files are following the source structure.
47
-
48
- If you want to merge all declarations into one file, just specify `rollupTypes: true`:
49
-
50
- ```ts
51
- {
52
- plugins: [dts({ rollupTypes: true })]
53
- }
54
- ```
55
-
56
- Starting with `3.0.0`, you can use this plugin with Rollup.
57
-
58
- ## FAQ
59
-
60
- Here are some FAQ's and solutions.
61
-
62
- ### Type errors that are unable to infer types from packages in `node_modules`
63
-
64
- This is an existing [TypeScript issue](https://github.com/microsoft/TypeScript/issues/42873) where TypeScript infers types from packages located in `node_modules` through soft links (pnpm). A workaround is to add `baseUrl` to your `tsconfig.json` and specify the `paths` for these packages:
65
-
66
- ```json
67
- {
68
- "compilerOptions": {
69
- "baseUrl": ".",
70
- "paths": {
71
- "third-lib": ["node_modules/third-lib"]
72
- }
73
- }
74
- }
75
- ```
76
-
77
- ### `Internal Error` occurs when using `rollupTypes: true`
78
-
79
- Refer to this [issue](https://github.com/microsoft/rushstack/issues/3875), it's due to a limitation of `@microsoft/api-extractor` or TypeScript resolver.
80
-
81
- The main reason is that `baseUrl` is specified in `tsconfig.json` and non-standard paths are used directly when imported.
82
-
83
- For example: `baseUrl: 'src'` is specified and importing from `<root>/src/components/index.ts` in `<root>/src/index.ts`, and `import 'components'` is used instead of `import './components'`.
84
-
85
- Currently, you need to avoid the above situation, or use aliases instead (with the `paths` option).
86
-
87
- ### Get module not found errors during build
88
-
89
- This is likely due to incorrect configuration of the `include` property in your default `tsconfig.json`.
90
-
91
- Due to some limitations, the plugin relies on the top-level `tsconfig.json` to resolve the files to include. Therefore, you need to specify the correct `include` property in the top-level `tsconfig.json`, or you can specify a configuration file path with the correct `include` property using the `tsconfigPath` option of the plugin. For example, in the Vite initial template, it is `tsconfig.app.json`.
92
-
93
- You can refer to this [comment](https://github.com/qmhc/vite-plugin-dts/issues/343#issuecomment-2198111439).
94
-
95
- <details>
96
- <summary>Legacy</summary>
97
-
98
- ### Missing some declaration files after build (before `1.7.0`)
99
-
100
- By default, the `skipDiagnostics` option is set to `true` which means type diagnostics will be skipped during the build process (some projects may have diagnostic tools such as `vue-tsc`). Files with type errors which interrupt the build process will not be emitted (declaration files won't be generated).
101
-
102
- If your project doesn't use type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on diagnostic and logging features of this plugin. Type errors during build will be logged to the terminal.
103
-
104
- ### Type error when using both `script` and `setup-script` in Vue component (before `3.0.0`)
105
-
106
- This is usually caused by using the `defineComponent` function in both `script` and `setup-script`. When `vue/compiler-sfc` compiles these files, the default export result from `script` gets merged with the parameter object of `defineComponent` from `setup-script`. This is incompatible with parameters and types returned from `defineComponent`. This results in a type error.
107
-
108
- Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue). You should remove the `defineComponent` in `script` and export a native object directly.
109
-
110
- </details>
111
-
112
- ## Options
113
-
114
- ```ts
115
- import type ts from 'typescript'
116
- import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
117
- import type { LogLevel } from 'vite'
118
-
119
- type MaybePromise<T> = T | Promise<T>
120
-
121
- export type RollupConfig = Omit<
122
- IExtractorConfigPrepareOptions['configObject'],
123
- | 'projectFolder'
124
- | 'mainEntryPointFilePath'
125
- | 'compiler'
126
- | 'dtsRollup'
127
- >
128
-
129
- export interface Resolver {
130
- /**
131
- * The name of the resolver
132
- *
133
- * The later resolver with the same name will overwrite the earlier
134
- */
135
- name: string,
136
- /**
137
- * Determine whether the resolver supports the file
138
- */
139
- supports: (id: string) => void | boolean,
140
- /**
141
- * Transform source to declaration files
142
- *
143
- * Note that the path of the returns should base on `outDir`, or relative path to `root`
144
- */
145
- transform: (payload: {
146
- id: string,
147
- code: string,
148
- root: string,
149
- outDir: string,
150
- host: ts.CompilerHost,
151
- program: ts.Program,
152
- service: ts.LanguageService
153
- }) => MaybePromise<{ path: string, content: string }[]>
154
- }
155
-
156
- export interface PluginOptions {
157
- /**
158
- * Specify root directory
159
- *
160
- * Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
161
- */
162
- root?: string,
163
-
164
- /**
165
- * Output directory for declaration files
166
- *
167
- * Can be an array to output to multiple directories
168
- *
169
- * Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
170
- */
171
- outDir?: string | string[],
172
-
173
- /**
174
- * Override root path of entry files (useful in monorepos)
175
- *
176
- * The output path of each file will be calculated based on the value provided
177
- *
178
- * The default is the smallest public path for all source files
179
- */
180
- entryRoot?: string,
181
-
182
- /**
183
- * Restrict declaration files output to `outDir`
184
- *
185
- * If true, generated declaration files outside `outDir` will be ignored
186
- *
187
- * @default true
188
- */
189
- strictOutput?: boolean,
190
-
191
- /**
192
- * Override compilerOptions
193
- *
194
- * @default null
195
- */
196
- compilerOptions?: ts.CompilerOptions | null,
197
-
198
- /**
199
- * Specify tsconfig.json path
200
- *
201
- * Plugin resolves `include` and `exclude` globs from tsconfig.json
202
- *
203
- * If not specified, plugin will find config file from root
204
- */
205
- tsconfigPath?: string,
206
-
207
- /**
208
- * Specify custom resolvers
209
- *
210
- * @default []
211
- */
212
- resolvers?: Resolver[],
213
-
214
- /**
215
- * Parsing `paths` of tsconfig.json to aliases
216
- *
217
- * Note that these aliases only use for declaration files
218
- *
219
- * @default true
220
- * @remarks Only use first replacement of each path
221
- */
222
- pathsToAliases?: boolean,
223
-
224
- /**
225
- * Set which paths should be excluded when transforming aliases
226
- *
227
- * @default []
228
- */
229
- aliasesExclude?: (string | RegExp)[],
230
-
231
- /**
232
- * Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
233
- *
234
- * @default false
235
- */
236
- cleanVueFileName?: boolean,
237
-
238
- /**
239
- * Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
240
- *
241
- * Value is forced to `true` when `rollupTypes` is `true`
242
- *
243
- * @default false
244
- */
245
- staticImport?: boolean,
246
-
247
- /**
248
- * Override `include` glob (relative to root)
249
- *
250
- * Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
251
- */
252
- include?: string | string[],
253
-
254
- /**
255
- * Override `exclude` glob
256
- *
257
- * Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
258
- */
259
- exclude?: string | string[],
260
-
261
- /**
262
- * Whether to remove `import 'xxx'`
263
- *
264
- * @default true
265
- */
266
- clearPureImport?: boolean,
267
-
268
- /**
269
- * Whether to generate types entry file(s)
270
- *
271
- * When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
272
- *
273
- * Value is forced to `true` when `rollupTypes` is `true`
274
- *
275
- * @default false
276
- */
277
- insertTypesEntry?: boolean,
278
-
279
- /**
280
- * Rollup type declaration files after emitting them
281
- *
282
- * Powered by `@microsoft/api-extractor` - time-intensive operation
283
- *
284
- * @default false
285
- */
286
- rollupTypes?: boolean,
287
-
288
- /**
289
- * Bundled packages for `@microsoft/api-extractor`
290
- *
291
- * @default []
292
- * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
293
- */
294
- bundledPackages?: string[],
295
-
296
- /**
297
- * Override the config of `@microsoft/api-extractor`
298
- *
299
- * @default null
300
- * @see https://api-extractor.com/pages/setup/configure_api_report/
301
- */
302
- rollupConfig?: RollupConfig,
303
-
304
- /**
305
- * Override the invoke options of `@microsoft/api-extractor`
306
- *
307
- * @default null
308
- * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
309
- */
310
- rollupOptions?: IExtractorInvokeOptions,
311
-
312
- /**
313
- * Whether to copy .d.ts source files to `outDir`
314
- *
315
- * @default false
316
- * @remarks Before 2.0, the default was `true`
317
- */
318
- copyDtsFiles?: boolean,
319
-
320
- /**
321
- * Whether to emit declaration files only
322
- *
323
- * When `true`, all the original outputs of vite (rollup) will be force removed
324
- *
325
- * @default false
326
- */
327
- declarationOnly?: boolean,
328
-
329
- /**
330
- * Logging level for this plugin
331
- *
332
- * Defaults to the 'logLevel' property of your Vite config
333
- */
334
- logLevel?: LogLevel,
335
-
336
- /**
337
- * Hook called after diagnostic is emitted
338
- *
339
- * According to the `diagnostics.length`, you can judge whether there is any type error
340
- *
341
- * @default () => {}
342
- */
343
- afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>,
344
-
345
- /**
346
- * Hook called prior to writing each declaration file
347
- *
348
- * This allows you to transform the path or content
349
- *
350
- * The file will be skipped when the return value `false` or `Promise<false>`
351
- *
352
- * @default () => {}
353
- */
354
- beforeWriteFile?: (
355
- filePath: string,
356
- content: string
357
- ) => MaybePromise<
358
- | void
359
- | false
360
- | {
361
- filePath?: string,
362
- content?: string
363
- }
364
- >,
365
-
366
- /**
367
- * Hook called after rolling up declaration files
368
- *
369
- * @default () => {}
370
- */
371
- afterRollup?: (result: ExtractorResult) => MaybePromise<void>,
372
-
373
- /**
374
- * Hook called after all declaration files are written
375
- *
376
- * It will be received a map (path -> content) that records those emitted files
377
- *
378
- * @default () => {}
379
- */
380
- afterBuild?: () => MaybePromise<void>
381
- }
382
- ```
383
-
384
- ## Contributors
385
-
386
- Thanks for all the contributions!
387
-
388
- <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
389
- <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" alt="contributors" />
390
- </a>
391
-
392
- ## Example
393
-
394
- Clone and run the following script:
395
-
396
- ```sh
397
- pnpm run test:ts
398
- ```
399
-
400
- Then check `examples/ts/types`.
401
-
402
- Also Vue and React cases under `examples`.
403
-
404
- A real project using this plugin: [Vexip UI](https://github.com/vexip-ui/vexip-ui).
405
-
406
- ## License
407
-
408
- MIT License.
1
+ <h1 align="center">vite-plugin-dts</h1>
2
+
3
+ <p align="center">
4
+ A Vite plugin that generates declaration files (<code>*.d.ts</code>) from <code>.ts(x)</code> or <code>.vue</code> source files when using Vite in <a href="https://vitejs.dev/guide/build.html#library-mode">library mode</a>.
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/vite-plugin-dts">
9
+ <img src="https://img.shields.io/npm/v/vite-plugin-dts?color=orange&label=" alt="version" />
10
+ </a>
11
+ <a href="https://github.com/qmhc/vite-plugin-dts/blob/main/LICENSE">
12
+ <img src="https://img.shields.io/npm/l/vite-plugin-dts" alt="license" />
13
+ </a>
14
+ </p>
15
+
16
+ **English** | [中文](./README.zh-CN.md)
17
+
18
+ ## Install
19
+
20
+ ```sh
21
+ pnpm i vite-plugin-dts -D
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ In `vite.config.ts`:
27
+
28
+ ```ts
29
+ import { resolve } from 'path'
30
+ import { defineConfig } from 'vite'
31
+ import dts from 'vite-plugin-dts'
32
+
33
+ export default defineConfig({
34
+ build: {
35
+ lib: {
36
+ entry: resolve(__dirname, 'src/index.ts'),
37
+ name: 'MyLib',
38
+ formats: ['es'],
39
+ fileName: 'my-lib'
40
+ }
41
+ },
42
+ plugins: [dts()]
43
+ })
44
+ ```
45
+
46
+ By default, the generated declaration files are following the source structure.
47
+
48
+ If you want to merge all declarations into one file, just specify `rollupTypes: true`:
49
+
50
+ ```ts
51
+ {
52
+ plugins: [dts({ rollupTypes: true })]
53
+ }
54
+ ```
55
+
56
+ Starting with `3.0.0`, you can use this plugin with Rollup.
57
+
58
+ ## FAQ
59
+
60
+ Here are some FAQ's and solutions.
61
+
62
+ ### Type errors that are unable to infer types from packages in `node_modules`
63
+
64
+ This is an existing [TypeScript issue](https://github.com/microsoft/TypeScript/issues/42873) where TypeScript infers types from packages located in `node_modules` through soft links (pnpm). A workaround is to add `baseUrl` to your `tsconfig.json` and specify the `paths` for these packages:
65
+
66
+ ```json
67
+ {
68
+ "compilerOptions": {
69
+ "baseUrl": ".",
70
+ "paths": {
71
+ "third-lib": ["node_modules/third-lib"]
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### `Internal Error` occurs when using `rollupTypes: true`
78
+
79
+ Refer to this [issue](https://github.com/microsoft/rushstack/issues/3875), it's due to a limitation of `@microsoft/api-extractor` or TypeScript resolver.
80
+
81
+ The main reason is that `baseUrl` is specified in `tsconfig.json` and non-standard paths are used directly when imported.
82
+
83
+ For example: `baseUrl: 'src'` is specified and importing from `<root>/src/components/index.ts` in `<root>/src/index.ts`, and `import 'components'` is used instead of `import './components'`.
84
+
85
+ Currently, you need to avoid the above situation, or use aliases instead (with the `paths` option).
86
+
87
+ ### Get module not found errors during build
88
+
89
+ This is likely due to incorrect configuration of the `include` property in your default `tsconfig.json`.
90
+
91
+ Due to some limitations, the plugin relies on the top-level `tsconfig.json` to resolve the files to include. Therefore, you need to specify the correct `include` property in the top-level `tsconfig.json`, or you can specify a configuration file path with the correct `include` property using the `tsconfigPath` option of the plugin. For example, in the Vite initial template, it is `tsconfig.app.json`.
92
+
93
+ You can refer to this [comment](https://github.com/qmhc/vite-plugin-dts/issues/343#issuecomment-2198111439).
94
+
95
+ <details>
96
+ <summary>Legacy</summary>
97
+
98
+ ### Missing some declaration files after build (before `1.7.0`)
99
+
100
+ By default, the `skipDiagnostics` option is set to `true` which means type diagnostics will be skipped during the build process (some projects may have diagnostic tools such as `vue-tsc`). Files with type errors which interrupt the build process will not be emitted (declaration files won't be generated).
101
+
102
+ If your project doesn't use type diagnostic tools, you can set `skipDiagnostics: false` and `logDiagnostics: true` to turn on diagnostic and logging features of this plugin. Type errors during build will be logged to the terminal.
103
+
104
+ ### Type error when using both `script` and `setup-script` in Vue component (before `3.0.0`)
105
+
106
+ This is usually caused by using the `defineComponent` function in both `script` and `setup-script`. When `vue/compiler-sfc` compiles these files, the default export result from `script` gets merged with the parameter object of `defineComponent` from `setup-script`. This is incompatible with parameters and types returned from `defineComponent`. This results in a type error.
107
+
108
+ Here is a simple [example](https://github.com/qmhc/vite-plugin-dts/blob/main/examples/vue/components/BothScripts.vue). You should remove the `defineComponent` in `script` and export a native object directly.
109
+
110
+ </details>
111
+
112
+ ## Options
113
+
114
+ ```ts
115
+ import type ts from 'typescript'
116
+ import type { IExtractorConfigPrepareOptions, IExtractorInvokeOptions } from '@microsoft/api-extractor'
117
+ import type { LogLevel } from 'vite'
118
+
119
+ type MaybePromise<T> = T | Promise<T>
120
+
121
+ export type RollupConfig = Omit<
122
+ IExtractorConfigPrepareOptions['configObject'],
123
+ | 'projectFolder'
124
+ | 'mainEntryPointFilePath'
125
+ | 'compiler'
126
+ | 'dtsRollup'
127
+ >
128
+
129
+ export interface Resolver {
130
+ /**
131
+ * The name of the resolver
132
+ *
133
+ * The later resolver with the same name will overwrite the earlier
134
+ */
135
+ name: string,
136
+ /**
137
+ * Determine whether the resolver supports the file
138
+ */
139
+ supports: (id: string) => void | boolean,
140
+ /**
141
+ * Transform source to declaration files
142
+ *
143
+ * Note that the path of the returns should base on `outDir`, or relative path to `root`
144
+ */
145
+ transform: (payload: {
146
+ id: string,
147
+ code: string,
148
+ root: string,
149
+ outDir: string,
150
+ host: ts.CompilerHost,
151
+ program: ts.Program,
152
+ service: ts.LanguageService
153
+ }) => MaybePromise<{ path: string, content: string }[]>
154
+ }
155
+
156
+ export interface PluginOptions {
157
+ /**
158
+ * Specify root directory
159
+ *
160
+ * Defaults to the 'root' of the Vite config, or `process.cwd()` if using Rollup
161
+ */
162
+ root?: string,
163
+
164
+ /**
165
+ * Output directory for declaration files
166
+ *
167
+ * Can be an array to output to multiple directories
168
+ *
169
+ * Defaults to 'build.outDir' of the Vite config, or `outDir` of tsconfig.json if using Rollup
170
+ */
171
+ outDir?: string | string[],
172
+
173
+ /**
174
+ * Override root path of entry files (useful in monorepos)
175
+ *
176
+ * The output path of each file will be calculated based on the value provided
177
+ *
178
+ * The default is the smallest public path for all source files
179
+ */
180
+ entryRoot?: string,
181
+
182
+ /**
183
+ * Restrict declaration files output to `outDir`
184
+ *
185
+ * If true, generated declaration files outside `outDir` will be ignored
186
+ *
187
+ * @default true
188
+ */
189
+ strictOutput?: boolean,
190
+
191
+ /**
192
+ * Override compilerOptions
193
+ *
194
+ * @default null
195
+ */
196
+ compilerOptions?: ts.CompilerOptions | null,
197
+
198
+ /**
199
+ * Specify tsconfig.json path
200
+ *
201
+ * Plugin resolves `include` and `exclude` globs from tsconfig.json
202
+ *
203
+ * If not specified, plugin will find config file from root
204
+ */
205
+ tsconfigPath?: string,
206
+
207
+ /**
208
+ * Specify custom resolvers
209
+ *
210
+ * @default []
211
+ */
212
+ resolvers?: Resolver[],
213
+
214
+ /**
215
+ * Parsing `paths` of tsconfig.json to aliases
216
+ *
217
+ * Note that these aliases only use for declaration files
218
+ *
219
+ * @default true
220
+ * @remarks Only use first replacement of each path
221
+ */
222
+ pathsToAliases?: boolean,
223
+
224
+ /**
225
+ * Set which paths should be excluded when transforming aliases
226
+ *
227
+ * @default []
228
+ */
229
+ aliasesExclude?: (string | RegExp)[],
230
+
231
+ /**
232
+ * Whether to transform file names ending in '.vue.d.ts' to '.d.ts'
233
+ *
234
+ * @default false
235
+ */
236
+ cleanVueFileName?: boolean,
237
+
238
+ /**
239
+ * Whether to transform dynamic imports to static (eg `import('vue').DefineComponent` to `import { DefineComponent } from 'vue'`)
240
+ *
241
+ * Value is forced to `true` when `rollupTypes` is `true`
242
+ *
243
+ * @default false
244
+ */
245
+ staticImport?: boolean,
246
+
247
+ /**
248
+ * Override `include` glob (relative to root)
249
+ *
250
+ * Defaults to `include` property of tsconfig.json (relative to tsconfig.json located)
251
+ */
252
+ include?: string | string[],
253
+
254
+ /**
255
+ * Override `exclude` glob
256
+ *
257
+ * Defaults to `exclude` property of tsconfig.json or `'node_modules/**'` if not supplied.
258
+ */
259
+ exclude?: string | string[],
260
+
261
+ /**
262
+ * Whether to remove `import 'xxx'`
263
+ *
264
+ * @default true
265
+ */
266
+ clearPureImport?: boolean,
267
+
268
+ /**
269
+ * Whether to generate types entry file(s)
270
+ *
271
+ * When `true`, uses package.json `types` property if it exists or `${outDir}/index.d.ts`
272
+ *
273
+ * Value is forced to `true` when `rollupTypes` is `true`
274
+ *
275
+ * @default false
276
+ */
277
+ insertTypesEntry?: boolean,
278
+
279
+ /**
280
+ * Rollup type declaration files after emitting them
281
+ *
282
+ * Powered by `@microsoft/api-extractor` - time-intensive operation
283
+ *
284
+ * @default false
285
+ */
286
+ rollupTypes?: boolean,
287
+
288
+ /**
289
+ * Bundled packages for `@microsoft/api-extractor`
290
+ *
291
+ * @default []
292
+ * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
293
+ */
294
+ bundledPackages?: string[],
295
+
296
+ /**
297
+ * Override the config of `@microsoft/api-extractor`
298
+ *
299
+ * @default null
300
+ * @see https://api-extractor.com/pages/setup/configure_api_report/
301
+ */
302
+ rollupConfig?: RollupConfig,
303
+
304
+ /**
305
+ * Override the invoke options of `@microsoft/api-extractor`
306
+ *
307
+ * @default null
308
+ * @see https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script
309
+ */
310
+ rollupOptions?: IExtractorInvokeOptions,
311
+
312
+ /**
313
+ * Whether to copy .d.ts source files to `outDir`
314
+ *
315
+ * @default false
316
+ * @remarks Before 2.0, the default was `true`
317
+ */
318
+ copyDtsFiles?: boolean,
319
+
320
+ /**
321
+ * Whether to emit declaration files only
322
+ *
323
+ * When `true`, all the original outputs of vite (rollup) will be force removed
324
+ *
325
+ * @default false
326
+ */
327
+ declarationOnly?: boolean,
328
+
329
+ /**
330
+ * Logging level for this plugin
331
+ *
332
+ * Defaults to the 'logLevel' property of your Vite config
333
+ */
334
+ logLevel?: LogLevel,
335
+
336
+ /**
337
+ * Hook called after diagnostic is emitted
338
+ *
339
+ * According to the `diagnostics.length`, you can judge whether there is any type error
340
+ *
341
+ * @default () => {}
342
+ */
343
+ afterDiagnostic?: (diagnostics: readonly ts.Diagnostic[]) => MaybePromise<void>,
344
+
345
+ /**
346
+ * Hook called prior to writing each declaration file
347
+ *
348
+ * This allows you to transform the path or content
349
+ *
350
+ * The file will be skipped when the return value `false` or `Promise<false>`
351
+ *
352
+ * @default () => {}
353
+ */
354
+ beforeWriteFile?: (
355
+ filePath: string,
356
+ content: string
357
+ ) => MaybePromise<
358
+ | void
359
+ | false
360
+ | {
361
+ filePath?: string,
362
+ content?: string
363
+ }
364
+ >,
365
+
366
+ /**
367
+ * Hook called after rolling up declaration files
368
+ *
369
+ * @default () => {}
370
+ */
371
+ afterRollup?: (result: ExtractorResult) => MaybePromise<void>,
372
+
373
+ /**
374
+ * Hook called after all declaration files are written
375
+ *
376
+ * It will be received a map (path -> content) that records those emitted files
377
+ *
378
+ * @default () => {}
379
+ */
380
+ afterBuild?: () => MaybePromise<void>
381
+ }
382
+ ```
383
+
384
+ ## Contributors
385
+
386
+ Thanks for all the contributions!
387
+
388
+ <a href="https://github.com/qmhc/vite-plugin-dts/graphs/contributors">
389
+ <img src="https://contrib.rocks/image?repo=qmhc/vite-plugin-dts" alt="contributors" />
390
+ </a>
391
+
392
+ ## Example
393
+
394
+ Clone and run the following script:
395
+
396
+ ```sh
397
+ pnpm run test:ts
398
+ ```
399
+
400
+ Then check `examples/ts/types`.
401
+
402
+ Also Vue and React cases under `examples`.
403
+
404
+ A real project using this plugin: [Vexip UI](https://github.com/vexip-ui/vexip-ui).
405
+
406
+ ## License
407
+
408
+ MIT License.