Skip to content

marmotte / vite/dts

vite/dts

Interfaces

PluginOptions

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:43

Properties

afterBuild()?

optional afterBuild: (emittedFiles) => MaybePromise<void>

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:237

Hook called after all declaration files are written.

It will be received a map (path -> content) that records those emitted files.

Parameters
emittedFiles

Map<string, string>

Returns

MaybePromise<void>

Default
ts
() => {}
afterDiagnostic()?

optional afterDiagnostic: (diagnostics) => MaybePromise<void>

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:210

Hook called after diagnostic is emitted.

According to the diagnostics.length, you can judge whether there is any type error.

Parameters
diagnostics

readonly Diagnostic[]

Returns

MaybePromise<void>

Default
ts
() => {}
afterRollup()?

optional afterRollup: (result) => MaybePromise<void>

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:229

Hook called after rolling up declaration files.

Parameters
result

ExtractorResult

Returns

MaybePromise<void>

Default
ts
() => {}
aliasesExclude?

optional aliasesExclude: (string | RegExp)[]

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:108

Set which paths should be excluded when transforming aliases.

Default
ts
[]
beforeWriteFile()?

optional beforeWriteFile: (filePath, content) => MaybePromise<false | void | { content?: string; filePath?: string; }>

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:220

Hook called prior to writing each declaration file.

This allows you to transform the path or content.

The file will be skipped when the return value false or Promise<false>.

Parameters
filePath

string

content

string

Returns

MaybePromise<false | void | { content?: string; filePath?: string; }>

Default
ts
() => {}
bundledPackages?

optional bundledPackages: string[]

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:167

Bundled packages for @microsoft/api-extractor.

Default
ts
[]
See

https://api-extractor.com/pages/configs/api-extractor_json/#bundledpackages

cleanVueFileName?

optional cleanVueFileName: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:116

Whether to transform file names ending in '.vue.d.ts' to '.d.ts'.

If there is a duplicate name after transform, it will fall back to the original name.

Default
ts
false
clearPureImport?

optional clearPureImport: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:142

Whether to remove import 'xxx'.

Default
ts
true
compilerOptions?

optional compilerOptions: CompilerOptions | null

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:79

Override compilerOptions.

Default
ts
null
copyDtsFiles?

optional copyDtsFiles: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:188

Whether to copy .d.ts source files to outDir.

Default
ts
false
Remarks

Before 2.0, the default was true.

declarationOnly?

optional declarationOnly: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:196

Whether to emit declaration files only.

When true, all the original outputs of vite (rollup) will be force removed.

Default
ts
false
entryRoot?

optional entryRoot: string

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:65

Override root path of entry files (useful in monorepos).

The output path of each file will be calculated based on the value provided.

The default is the smallest public path for all source files.

exclude?

optional exclude: string | string[]

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:136

Override exclude glob.

Defaults to exclude property of tsconfig.json or 'node_modules/**' if not supplied.

include?

optional include: string | string[]

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:130

Override include glob (relative to root).

Defaults to include property of tsconfig.json (relative to tsconfig.json located).

insertTypesEntry?

optional insertTypesEntry: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:152

Whether to generate types entry file(s).

When true, uses package.json types property if it exists or ${outDir}/index.d.ts.

Value is forced to true when rollupTypes is true.

Default
ts
false
logLevel?

optional logLevel: LogLevel

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:202

Logging level for this plugin.

Defaults to the 'logLevel' property of your Vite config.

outDir?

optional outDir: string | string[]

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:57

Output directory for declaration files.

Can be an array to output to multiple directories.

Defaults to 'build.outDir' of the Vite config, or outDir of tsconfig.json if using Rollup.

pathsToAliases?

optional pathsToAliases: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:102

Parsing paths of tsconfig.json to aliases.

Note that these aliases only use for declaration files.

Default
ts
true
Remarks

Only use first replacement of each path.

resolvers?

optional resolvers: Resolver[]

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:93

Specify custom resolvers.

Default
ts
[]
rollupConfig?

optional rollupConfig: RollupConfig

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:174

Override the config of @microsoft/api-extractor.

Default
ts
null
See

https://api-extractor.com/pages/setup/configure_api_report/

rollupOptions?

optional rollupOptions: IExtractorInvokeOptions

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:181

Override the invoke options of @microsoft/api-extractor.

Default
ts
null
See

https://api-extractor.com/pages/setup/invoking/#invoking-from-a-build-script

rollupTypes?

optional rollupTypes: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:160

Rollup type declaration files after emitting them.

Powered by @microsoft/api-extractor - time-intensive operation.

Default
ts
false
root?

optional root: string

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:49

Specify root directory.

Defaults to the 'root' of the Vite config, or process.cwd() if using Rollup.

staticImport?

optional staticImport: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:124

Whether to transform dynamic imports to static (eg import('vue').DefineComponent to import { DefineComponent } from 'vue').

Value is forced to true when rollupTypes is true.

Default
ts
false
strictOutput?

optional strictOutput: boolean

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:73

Restrict declaration files output to outDir.

If true, generated declaration files outside outDir will be ignored.

Default
ts
true
tsconfigPath?

optional tsconfigPath: string

Defined in: node_modules/vite-plugin-dts/dist/index.d.ts:87

Specify tsconfig.json path.

Plugin resolves include and exclude globs from tsconfig.json.

If not specified, plugin will find config file from root.

Functions

default()

default(options?): object

Defined in: src/vite/dts.ts:14

A wrapper around vite-plugin-dts that also exposes the options so that other plugins can use the same TS config without having to copy paste settings

Parameters

options?

PluginOptions = {}

Returns

api

api: object

api.options

options: PluginOptions

apply?

optional apply: "serve" | "build" | (this, config, env) => boolean

Apply the plugin only for serve or build, or on certain conditions.

applyToEnvironment()?

optional applyToEnvironment: (environment) => true | PluginOption | Promise<boolean>

Experimental

Define environments where this plugin should be active By default, the plugin is active in all environments

Parameters
environment

PartialEnvironment

Returns

true | PluginOption | Promise<boolean>

augmentChunkHash?

optional augmentChunkHash: ObjectHook<(this, chunk) => string | void, { }>

optional banner: ObjectHook<AddonHook, { }>

buildApp?

optional buildApp: ObjectHook<BuildAppHook>

Experimental

Build Environments

buildEnd?

optional buildEnd: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

buildStart?

optional buildStart: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

cacheKey?

optional cacheKey: string

closeBundle?

optional closeBundle: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

closeWatcher?

optional closeWatcher: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

config?

optional config: ObjectHook<(this, config, env) => void | Omit<UserConfig, "plugins"> | Promise<void | Omit<UserConfig, "plugins"> | null> | null>

Modify vite config before it's resolved. The hook can either mutate the passed-in config directly, or return a partial config object that will be deeply merged into existing config.

Note: User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect.

configEnvironment?

optional configEnvironment: ObjectHook<(this, name, config, env) => void | EnvironmentOptions | Promise<void | EnvironmentOptions | null> | null>

Modify environment configs before it's resolved. The hook can either mutate the passed-in environment config directly, or return a partial config object that will be deeply merged into existing config. This hook is called for each environment with a partially resolved environment config that already accounts for the default environment config values set at the root level. If plugins need to modify the config of a given environment, they should do it in this hook instead of the config hook. Leaving the config hook only for modifying the root default environment config.

configResolved?

optional configResolved: ObjectHook<(this, config) => void | Promise<void>>

Use this hook to read and store the final resolved vite config.

configurePreviewServer?

optional configurePreviewServer: ObjectHook<PreviewServerHook>

Configure the preview server. The hook receives the PreviewServer instance. This can also be used to store a reference to the server for use in other hooks.

The hooks are called before other middlewares are applied. A hook can return a post hook that will be called after other middlewares are applied. Hooks can be async functions and will be called in series.

configureServer?

optional configureServer: ObjectHook<ServerHook>

Configure the vite server. The hook receives the ViteDevServer instance. This can also be used to store a reference to the server for use in other hooks.

The hooks will be called before internal middlewares are applied. A hook can return a post hook that will be called after internal middlewares are applied. Hook can be async functions and will be called in series.

enforce?

optional enforce: "pre" | "post"

Enforce plugin invocation tier similar to webpack loaders. Hooks ordering is still subject to the order property in the hook object.

Plugin invocation order:

  • alias resolution
  • enforce: 'pre' plugins
  • vite core plugins
  • normal plugins
  • vite build plugins
  • enforce: 'post' plugins
  • vite build post plugins

optional footer: ObjectHook<AddonHook, { }>

generateBundle?

optional generateBundle: ObjectHook<(this, ...parameters) => void | Promise<void>, { }>

handleHotUpdate?

optional handleHotUpdate: ObjectHook<(this, ctx) => void | ModuleNode[] | Promise<void | ModuleNode[]>>

Perform custom handling of HMR updates. The handler receives a context containing changed filename, timestamp, a list of modules affected by the file change, and the dev server instance.

  • The hook can return a filtered list of modules to narrow down the update. e.g. for a Vue SFC, we can narrow down the part to update by comparing the descriptors.

  • The hook can also return an empty array and then perform custom updates by sending a custom hmr payload via server.ws.send().

  • If the hook doesn't return a value, the hmr update will be performed as normal.

hotUpdate?

optional hotUpdate: ObjectHook<(this, options) => void | EnvironmentModuleNode[] | Promise<void | EnvironmentModuleNode[]>>

Perform custom handling of HMR updates. The handler receives an options containing changed filename, timestamp, a list of modules affected by the file change, and the dev server instance.

  • The hook can return a filtered list of modules to narrow down the update. e.g. for a Vue SFC, we can narrow down the part to update by comparing the descriptors.

  • The hook can also return an empty array and then perform custom updates by sending a custom hmr payload via environment.hot.send().

  • If the hook doesn't return a value, the hmr update will be performed as normal.

intro?

optional intro: ObjectHook<AddonHook, { }>

load?

optional load: ObjectHook<(this, id, options?) => LoadResult | Promise<LoadResult>, { filter?: { id?: StringFilter<string | RegExp> | undefined; }; }>

moduleParsed?

optional moduleParsed: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

name

name: string = PLUGIN_NAME

onLog?

optional onLog: ObjectHook<(this, level, log) => boolean | NullValue, { }>

options?

optional options: ObjectHook<(this, ...parameters) => NullValue | InputOptions | Promise<NullValue | InputOptions>, { }>

outputOptions?

optional outputOptions: ObjectHook<(this, options) => NullValue | OutputOptions, { }>

outro?

optional outro: ObjectHook<AddonHook, { }>

perEnvironmentStartEndDuringDev?

optional perEnvironmentStartEndDuringDev: boolean

Experimental

Opt-in this plugin into per-environment buildStart and buildEnd during dev. For backward-compatibility, the buildStart hook is called only once during dev, for the client environment. Plugins can opt-in to be called per-environment, aligning with the build hook behavior.

perEnvironmentWatchChangeDuringDev?

optional perEnvironmentWatchChangeDuringDev: boolean

Experimental

Opt-in this plugin into per-environment watchChange during dev. For backward-compatibility, the watchChange hook is called only once during dev, for the client environment. Plugins can opt-in to be called per-environment, aligning with the watchChange hook behavior.

renderChunk?

optional renderChunk: ObjectHook<(this, ...parameters) => string | NullValue | { code: string; map?: SourceMapInput | undefined; } | Promise<string | NullValue | { code: string; map?: SourceMapInput | undefined; }>, { }>

renderDynamicImport?

optional renderDynamicImport: ObjectHook<(this, options) => NullValue | { left: string; right: string; }, { }>

renderError?

optional renderError: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

renderStart?

optional renderStart: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

resolveDynamicImport?

optional resolveDynamicImport: ObjectHook<(this, ...parameters) => ResolveIdResult | Promise<ResolveIdResult>, { }>

resolveFileUrl?

optional resolveFileUrl: ObjectHook<ResolveFileUrlHook, { }>

resolveId?

optional resolveId: ObjectHook<(this, source, importer, options) => ResolveIdResult | Promise<ResolveIdResult>, { filter?: { id?: StringFilter<RegExp> | undefined; }; }>

extend hooks with ssr flag

resolveImportMeta?

optional resolveImportMeta: ObjectHook<ResolveImportMetaHook, { }>

sharedDuringBuild?

optional sharedDuringBuild: boolean

Experimental

Opt-in this plugin into the shared plugins pipeline. For backward-compatibility, plugins are re-recreated for each environment during vite build --app We have an opt-in per plugin, and a general builder.sharedPlugins In a future major, we'll flip the default to be shared by default

shouldTransformCachedModule?

optional shouldTransformCachedModule: ObjectHook<(this, ...parameters) => boolean | NullValue | Promise<boolean | NullValue>, { }>

transform?

optional transform: ObjectHook<(this, code, id, options?) => TransformResult | Promise<TransformResult>, { filter?: { code?: StringFilter<string | RegExp> | undefined; id?: StringFilter<string | RegExp> | undefined; }; }>

transformIndexHtml?

optional transformIndexHtml: IndexHtmlTransform

Transform index.html. The hook receives the following arguments:

  • html: string
  • ctx: IndexHtmlTransformContext, which contains:
    • path: public path when served
    • filename: filename on disk
    • server?: ViteDevServer (only present during serve)
    • bundle?: rollup.OutputBundle (only present during build)
    • chunk?: rollup.OutputChunk
    • originalUrl?: string

It can either return a transformed string, or a list of html tag descriptors that will be injected into the <head> or <body>.

By default the transform is applied after vite's internal html transform. If you need to apply the transform before vite, use an object: { order: 'pre', handler: hook }

version?

optional version: string

watchChange?

optional watchChange: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>

writeBundle?

optional writeBundle: ObjectHook<(this, ...parameters) => void | Promise<void>, { sequential?: boolean; }>


getDTSPlugin()

getDTSPlugin(config): object[]

Defined in: src/vite/dts.ts:26

Parameters

config

ResolvedConfig

Returns


getDTSPluginOptions()

getDTSPluginOptions(config): PluginOptions

Defined in: src/vite/dts.ts:30

Parameters

config

ResolvedConfig

Returns

PluginOptions