Skip to content

Commit a23d063

Browse files
biggerstarqmhc
andauthoredAug 4, 2023
feat: support emit declaration files only (#253)
* feat: support only output dts * chore: update api docs --------- Co-authored-by: qmhc <40221744+qmhc@users.noreply.github.com>
1 parent 3767fdf commit a23d063

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed
 

‎README.md

+9
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ export interface PluginOptions {
286286
*/
287287
copyDtsFiles?: boolean,
288288

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+
289298
/**
290299
* Logging level for this plugin
291300
*

‎README.zh-CN.md

+9
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ export interface PluginOptions {
286286
*/
287287
copyDtsFiles?: boolean,
288288

289+
/**
290+
* 是否只生成类型文件
291+
*
292+
* 当为 `true` 时会强制删除所有 Vite(Rollup)的原始产物
293+
*
294+
* @default false
295+
*/
296+
declarationOnly?: boolean,
297+
289298
/**
290299
* 指定插件的输出等级
291300
*

‎examples/ts/vite.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default defineConfig({
2727
// aliasesExclude: [/^@components/],
2828
staticImport: true,
2929
// insertTypesEntry: true,
30-
rollupTypes: true
30+
rollupTypes: true,
31+
declarationOnly: true
3132
})
3233
]
3334
})

‎src/plugin.ts

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
7676
pathsToAliases = true,
7777
aliasesExclude = [],
7878
copyDtsFiles = false,
79+
declarationOnly = false,
7980
strictOutput = true,
8081
afterDiagnostic = noop,
8182
beforeWriteFile = noop,
@@ -691,6 +692,13 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
691692
logger.info(
692693
green(`${logPrefix} Declaration files built in ${timeRecord + Date.now() - startTime}ms.\n`)
693694
)
695+
},
696+
generateBundle(_, bundle) {
697+
if (declarationOnly) {
698+
for (const id of Object.keys(bundle)) {
699+
delete bundle[id]
700+
}
701+
}
694702
}
695703
}
696704
}

‎src/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ export interface PluginOptions {
192192
*/
193193
copyDtsFiles?: boolean,
194194

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+
195204
/**
196205
* Logging level for this plugin
197206
*

0 commit comments

Comments
 (0)
Please sign in to comment.