vite-plugin-dts 2.3.0 → 3.0.0-beta.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.zh-CN.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <h1 align="center">vite-plugin-dts</h1>
2
2
 
3
3
  <p align="center">
4
- 一款用于在 <a href="https://cn.vitejs.dev/guide/build.html#library-mode">库模式</a> 中从 <code>.ts(x)</code> 或 <code>.vue</code> 源文件生成类型文件(<code>*.d.ts</code>)的 vite 插件。
4
+ 一款用于在 <a href="https://cn.vitejs.dev/guide/build.html#library-mode">库模式</a> 中从 <code>.ts(x)</code> 或 <code>.vue</code> 源文件生成类型文件(<code>*.d.ts</code>)的 Vite 插件。
5
5
  </p>
6
6
 
7
7
  <p align="center">
@@ -10,13 +10,7 @@
10
10
  </a>
11
11
  </p>
12
12
 
13
- <p align="center">
14
- <strong>中文</strong> | <a href="./README.md">English</a>
15
- </p>
16
-
17
- <p align="center"><strong>注意:</strong>从 1.7.0 开始 <code>skipDiagnostics</code> 选项默认为 <code>false</code>。</p>
18
-
19
- <br />
13
+ **中文** | [English](./README.md)
20
14
 
21
15
  ## 安装
22
16
 
@@ -86,7 +80,7 @@ const props = defineProps<{
86
80
 
87
81
  如果您的项目没有依赖外部的类型检查工具,这时候可以您可以设置 `skipDiagnostics: false` 和 `logDiagnostics: true` 来打开插件的诊断与输出功能,这将帮助您检查打包过程中出现的类型错误并将错误信息输出至终端。
88
82
 
89
- ### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误
83
+ ### Vue 组件中同时使用了 `script` 和 `setup-script` 后出现类型错误(`3.0.0` 之前)
90
84
 
91
85
  这通常是由于分别在 `script` 和 `setup-script` 中同时使用了 `defineComponent` 方法导致的。 `vue/compiler-sfc` 为这类文件编译时会将 `script` 中的默认导出结果合并到 `setup-script` 的 `defineComponent` 的参数定义中,而 `defineComponent` 的参数类型与结果类型并不兼容,这一行为将会导致类型错误。
92
86
 
@@ -110,7 +104,7 @@ const props = defineProps<{
110
104
  ## 选项
111
105
 
112
106
  ```ts
113
- import type { ts, Diagnostic } from 'ts-morph'
107
+ import type ts from 'typescript'
114
108
  import type { LogLevel } from 'vite'
115
109
 
116
110
  interface TransformWriteFile {
@@ -120,23 +114,23 @@ interface TransformWriteFile {
120
114
 
121
115
  export interface PluginOptions {
122
116
  /**
123
- * 执行的根目录
117
+ * 指定根目录
124
118
  *
125
- * 默认基于 vite 配置的 'root' 选项
119
+ * 默认基于 Vite 配置的 'root',使用 Rollup 时基于 `process.cwd()`
126
120
  */
127
121
  root?: string
128
122
 
129
123
  /**
130
- * 声明文件的输出目录
124
+ * 指定输出目录
131
125
  *
132
126
  * 可以指定一个数组来输出到多个目录中
133
127
  *
134
- * 默认基于 vite 配置的 'build.outDir' 选项
128
+ * 默认基于 Vite 配置的 'build.outDir',使用 Rollup 时基于 tsconfig.json 的 `outDir`
135
129
  */
136
- outputDir?: string | string[]
130
+ outDir?: string | string[]
137
131
 
138
132
  /**
139
- * 用于手动设置入口文件的根路径
133
+ * 用于手动设置入口文件的根路径,通常用在 monorepo
140
134
  *
141
135
  * 在计算每个文件的输出路径时将基于该路径
142
136
  *
@@ -145,26 +139,24 @@ export interface PluginOptions {
145
139
  entryRoot?: string
146
140
 
147
141
  /**
148
- * 提供给 ts-morph Project 初始化的 compilerOptions 选项
142
+ * 指定一个用于覆写的 CompilerOptions
149
143
  *
150
144
  * @default null
151
145
  */
152
146
  compilerOptions?: ts.CompilerOptions | null
153
147
 
154
148
  /**
155
- * 提供给 ts-morph Project 初始化的 tsconfig.json 路径
149
+ * 指定 tsconfig.json 的路径
156
150
  *
157
- * 插件也会读取 tsconfig.json 的 incldue 和 exclude 选项来解析文件
151
+ * 插件也会解析 tsconfig.json 的 include 和 exclude 选项
158
152
  *
159
- * @default 'tsconfig.json'
153
+ * 未指定时插件默认从根目录寻找配置
160
154
  */
161
- tsConfigFilePath?: string
155
+ tsconfigPath?: string
162
156
 
163
157
  /**
164
158
  * 设置在转换别名时哪些路径需要排除
165
159
  *
166
- * 如果为正则,会直接使用 test 和原始路径进行比较
167
- *
168
160
  * @default []
169
161
  */
170
162
  aliasesExclude?: (string | RegExp)[]
@@ -179,9 +171,9 @@ export interface PluginOptions {
179
171
  /**
180
172
  * 是否将动态引入转换为静态
181
173
  *
182
- * 当开启打包类型文件时强制为 true
174
+ * 开启 `rollupTypes` 时强制为 `true`
183
175
  *
184
- * 例如将 'import('vue').DefineComponent' 转换为 'import { DefineComponent } from "vue"'
176
+ * 例如将 `import('vue').DefineComponent` 转换为 `import { DefineComponent } from 'vue'`
185
177
  *
186
178
  * @default false
187
179
  */
@@ -190,19 +182,19 @@ export interface PluginOptions {
190
182
  /**
191
183
  * 手动设置包含路径的 glob
192
184
  *
193
- * 默认基于 tsconfig.json 的 'include' 选项
185
+ * 默认基于 tsconfig.json 的 `include` 选项
194
186
  */
195
187
  include?: string | string[]
196
188
 
197
189
  /**
198
190
  * 手动设置排除路径的 glob
199
191
  *
200
- * 默认基于 tsconfig.json 的 'exclude' 选线,未设置时为 'node_module/**'
192
+ * 默认基于 tsconfig.json 的 `exclude` 选线,未设置时为 `'node_module/**'`
201
193
  */
202
194
  exclude?: string | string[]
203
195
 
204
196
  /**
205
- * 如果文件内容仅包含 'export {}' 则跳过生成
197
+ * 是否移除那些 `import 'xxx'`
206
198
  *
207
199
  * @default true
208
200
  */
@@ -211,9 +203,9 @@ export interface PluginOptions {
211
203
  /**
212
204
  * 是否生成类型声明入口
213
205
  *
214
- * 当为 true 时会基于 package.json 的 types 字段生成,或者 `${outputDir}/index.d.ts`
206
+ * 当为 `true` 时会基于 package.json 的 types 字段生成,或者 `${outDir}/index.d.ts`
215
207
  *
216
- * 当开启打包类型文件时强制为 true
208
+ * 当开启打包类型文件时强制为 `true`
217
209
  *
218
210
  * @default false
219
211
  */
@@ -229,45 +221,25 @@ export interface PluginOptions {
229
221
  rollupTypes?: boolean
230
222
 
231
223
  /**
232
- * 是否将源码里的 .d.ts 文件复制到 outputDir
224
+ * 设置 `@microsoft/api-extractor` `bundledPackages` 选项
233
225
  *
234
- * @default false
235
- * @remarks 在 2.0 之前它默认为 true
236
- */
237
- copyDtsFiles?: boolean
238
-
239
- /**
240
- * 出现类型诊断信息时不生成类型文件
241
- *
242
- * @default false
226
+ * @default []
227
+ * @see https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages
243
228
  */
244
- noEmitOnError?: boolean
229
+ bundledPackages?: string[]
245
230
 
246
231
  /**
247
- * 是否跳过类型诊断
248
- *
249
- * 跳过类型诊断意味着出现错误时不会中断打包进程的执行
250
- *
251
- * 但对于出现错误的源文件,将无法生成相应的类型文件
232
+ * 是否将源码里的 .d.ts 文件复制到 `outDir`
252
233
  *
253
234
  * @default false
254
- * @remarks 在 1.7 之前它默认为 true
255
- */
256
- skipDiagnostics?: boolean
257
-
258
- /**
259
- * 定制 typescript 的 lib 文件夹路径
260
- *
261
- * 应传入一个 root 的相对路径或一个绝对路径
262
- *
263
- * @default undefined
235
+ * @remarks 在 2.0 之前它默认为 true
264
236
  */
265
- libFolderPath?: string
237
+ copyDtsFiles?: boolean
266
238
 
267
239
  /**
268
240
  * 指定插件的输出等级
269
241
  *
270
- * 默认基于 vite 配置的 'logLevel' 选项
242
+ * 默认基于 Vite 配置的 'logLevel' 选项
271
243
  */
272
244
  logLevel?: LogLevel
273
245
 
@@ -285,7 +257,7 @@ export interface PluginOptions {
285
257
  *
286
258
  * 可以在钩子里转换文件路径和文件内容
287
259
  *
288
- * 当返回 false 时会跳过该文件
260
+ * 当返回 `false` 时会跳过该文件
289
261
  *
290
262
  * @default () => {}
291
263
  */
@@ -320,6 +292,10 @@ pnpm run test:ts
320
292
 
321
293
  然后检查 `examples/ts/types` 目录。
322
294
 
295
+ `examples` 目录下同样有 Vue 和 React 的案例。
296
+
297
+ 一个使用该插件的真实项目:[Vexip UI](https://github.com/vexip-ui/vexip-ui)。
298
+
323
299
  ## 授权
324
300
 
325
301
  MIT 授权。