File tree 5 files changed +37
-1
lines changed
5 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -286,6 +286,15 @@ export interface PluginOptions {
286
286
*/
287
287
copyDtsFiles? : boolean ,
288
288
289
+ /**
290
+ * Whether to emit declaration files only
291
+ *
292
+ * When `true`, all the original outputs of vite (rollup) will be force removed
293
+ *
294
+ * @default false
295
+ */
296
+ declarationOnly? : boolean ,
297
+
289
298
/**
290
299
* Logging level for this plugin
291
300
*
Original file line number Diff line number Diff line change @@ -286,6 +286,15 @@ export interface PluginOptions {
286
286
*/
287
287
copyDtsFiles? : boolean ,
288
288
289
+ /**
290
+ * 是否只生成类型文件
291
+ *
292
+ * 当为 `true` 时会强制删除所有 Vite(Rollup)的原始产物
293
+ *
294
+ * @default false
295
+ */
296
+ declarationOnly? : boolean ,
297
+
289
298
/**
290
299
* 指定插件的输出等级
291
300
*
Original file line number Diff line number Diff line change @@ -27,7 +27,8 @@ export default defineConfig({
27
27
// aliasesExclude: [/^@components/],
28
28
staticImport : true ,
29
29
// insertTypesEntry: true,
30
- rollupTypes : true
30
+ rollupTypes : true ,
31
+ declarationOnly : true
31
32
} )
32
33
]
33
34
} )
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
76
76
pathsToAliases = true ,
77
77
aliasesExclude = [ ] ,
78
78
copyDtsFiles = false ,
79
+ declarationOnly = false ,
79
80
strictOutput = true ,
80
81
afterDiagnostic = noop ,
81
82
beforeWriteFile = noop ,
@@ -691,6 +692,13 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
691
692
logger . info (
692
693
green ( `${ logPrefix } Declaration files built in ${ timeRecord + Date . now ( ) - startTime } ms.\n` )
693
694
)
695
+ } ,
696
+ generateBundle ( _ , bundle ) {
697
+ if ( declarationOnly ) {
698
+ for ( const id of Object . keys ( bundle ) ) {
699
+ delete bundle [ id ]
700
+ }
701
+ }
694
702
}
695
703
}
696
704
}
Original file line number Diff line number Diff line change @@ -192,6 +192,15 @@ export interface PluginOptions {
192
192
*/
193
193
copyDtsFiles ?: boolean ,
194
194
195
+ /**
196
+ * Whether to emit declaration files only
197
+ *
198
+ * When `true`, all the original outputs of vite (rollup) will be force removed
199
+ *
200
+ * @default false
201
+ */
202
+ declarationOnly ?: boolean ,
203
+
195
204
/**
196
205
* Logging level for this plugin
197
206
*
You can’t perform that action at this time.
0 commit comments