undefined
Configure the generation of the TypeScript declaration files.
Declaration files generation is an optional feature, you can set dts: true
to enable bundleless declaration files generation.
If you want to disable declaration files generation, you can set dts: false
or do not specify the dts
option.
If you want to customize the declaration files generation, you can set the dts
option to an object.
boolean | { bundledPackages?: string[] }
false
Whether to bundle the declaration files.
If you want to bundle declaration files files, you should:
dts.bundle
to true
.string[]
Specifies the dependencies whose declaration files should be bundled. This configuration is passed to the bundledPackages option of @microsoft/api-extractor
.
By default, Rslib determines externalized dependencies based on the following configurations. For details, refer to Handle third-party dependencies.
Direct dependencies (declared in package.json
) that are not externalized will be automatically added to bundledPackages
, and their declaration files will be bundled into the final output.
When the default behavior does not meet the requirements, you can explicitly specify the dependencies whose declaration files need to be bundled through dts.bundle.bundledPackages
. After setting this configuration, the above default behavior will be completely overwritten.
This is typically used for bundling transitive dependencies (dependencies of direct dependencies). For example, if the project directly depends on foo
, and foo
depends on bar
, you can bundle both foo
and bar
's declaration files as follows:
bundledPackages
can be specified with the minimatch syntax, but will only match the declared direct dependencies in package.json
.
string
The output directory of declaration files.
The default value follows the priority below:
dts.distPath
value in the current lib configuration.declarationDir
value in the tsconfig.json
file.boolean
false
Whether to generate declaration files with building the project references. This is equivalent to using the --build
flag with the tsc
command. See Project References for more details.
When this option is enabled, you must explicitly set declarationDir
or outDir
in tsconfig.json
in order to meet the build requirements.
boolean
true
Whether to abort the build process when an error occurs during declaration files generation.
By default, type errors will cause the build to fail.
When abortOnError
is set to false
like below, the build will still succeed even if there are type issues in the code.
When this configuration is disabled, there is no guarantee that the type files will be generated correctly.
boolean
false
Whether to automatically set the declaration file extension based on the format option.
By default that when dts.autoExtension
is false
, the declaration file extension will be .d.ts
.
When dts.autoExtension
is set to true
, the declaration file extension will be:
.d.ts
with esm
format and .d.cts
with cjs
format when type: module
in package.json
.
.d.ts
with cjs
format and .d.mts
with esm
format when type: commonjs
or no type
field in package.json
.
It follows the same logic as lib.autoExtension, but the default value is different since the declaration file extension may cause some issues with different module resolution strategies.