Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support only output dts #253

Merged
merged 3 commits into from Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -286,6 +286,15 @@ export interface PluginOptions {
*/
copyDtsFiles?: boolean,

/**
* Whether to emit declaration files only
*
* When `true`, all the original outputs of vite (rollup) will be force removed
*
* @default false
*/
declarationOnly?: boolean,

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

/**
* 是否只生成类型文件
*
* 当为 `true` 时会强制删除所有 Vite(Rollup)的原始产物
*
* @default false
*/
declarationOnly?: boolean,

/**
* 指定插件的输出等级
*
Expand Down
3 changes: 2 additions & 1 deletion examples/ts/vite.config.ts
Expand Up @@ -27,7 +27,8 @@ export default defineConfig({
// aliasesExclude: [/^@components/],
staticImport: true,
// insertTypesEntry: true,
rollupTypes: true
rollupTypes: true,
declarationOnly: true
})
]
})
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 @@ -691,6 +692,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 id of Object.keys(bundle)) {
delete bundle[id]
}
}
}
}
}
9 changes: 9 additions & 0 deletions src/types.ts
Expand Up @@ -192,6 +192,15 @@ export interface PluginOptions {
*/
copyDtsFiles?: boolean,

/**
* Whether to emit declaration files only
*
* When `true`, all the original outputs of vite (rollup) will be force removed
*
* @default false
*/
declarationOnly?: boolean,

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