Skip to content

Commit

Permalink
feat: support only output dts
Browse files Browse the repository at this point in the history
  • Loading branch information
biggerstar committed Jul 30, 2023
1 parent e342242 commit 9ea29f7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -276,6 +276,15 @@ export interface PluginOptions {
*/
copyDtsFiles?: boolean,

/**
* Whether to output only dts
*
* Enabling this option will delete all the original products packaged with vite and only output the dts declaration file
*
* @default false
*/
declarationOnly?: boolean,

/**
* Logging level for this plugin
*
Expand Down
9 changes: 9 additions & 0 deletions README.zh-CN.md
Expand Up @@ -276,6 +276,15 @@ export interface PluginOptions {
*/
copyDtsFiles?: boolean,

/**
* 是否只输出dts产物
*
* 启用此选项将删除所有vite打包的产物,并且只会输出dts声明文件
*
* @default false
*/
declarationOnly?: boolean,

/**
* 指定插件的输出等级
*
Expand Down
8 changes: 8 additions & 0 deletions src/plugin.ts
Expand Up @@ -76,6 +76,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
pathsToAliases = true,
aliasesExclude = [],
copyDtsFiles = false,
declarationOnly = false,
strictOutput = true,
afterDiagnostic = noop,
beforeWriteFile = noop,
Expand Down Expand Up @@ -683,6 +684,13 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
logger.info(
green(`${logPrefix} Declaration files built in ${timeRecord + Date.now() - startTime}ms.\n`)
)
},
generateBundle(_, bundle) {
if (declarationOnly) {
for (const k in bundle) {
delete bundle[k]
}
}
}
}
}
9 changes: 9 additions & 0 deletions src/types.ts
Expand Up @@ -192,6 +192,15 @@ export interface PluginOptions {
*/
copyDtsFiles?: boolean,

/**
* Whether to output only dts
*
* Enabling this option will delete all the original products packaged with vite and only output the dts declaration file
*
* @default false
*/
declarationOnly?: boolean,

/**
* Logging level for this plugin
*
Expand Down

0 comments on commit 9ea29f7

Please sign in to comment.