Variable: dtsComplex()
const dtsComplex: (options?: Options) => Plugin<any> | Plugin<any>[];Advanced Vite plugin that generates TypeScript declaration files for library builds with intelligent vendor dependency bundling and path alias resolution.
Key Differences from @nhtio/vite-plugins/dts
While the standard dts plugin runs the entire pipeline through Microsoft API Extractor, dtsComplex uses a hybrid approach:
Native TypeScript Compilation: Your source files are compiled to
.d.tsusing TypeScript's native compiler, preserving original structure and comments.Selective API Extractor Usage: API Extractor is only used to bundle external vendor libraries into single declaration files, not for your entire codebase.
Separate Vendor Bundles: External dependencies are bundled into separate files (e.g.,
bundled_vendor_name.d.ts) and referenced from your main declarations, rather than being inlined.Path Alias Resolution: All import/export paths are resolved to relative paths, eliminating the need for consumers to configure
pathsin theirtsconfig.json.
Pre-Rolled vs Bundled Dependencies
Bundled Dependencies: Libraries that need to be rolled up using API Extractor because their declaration files are spread across multiple files.
Pre-Rolled Dependencies: Libraries that already provide a single rolled-up declaration file (or single declaration per subpath). These are extracted as-is without further processing.
Parameters
| Parameter | Type |
|---|---|
options? | Options |
Returns
Plugin<any> | Plugin<any>[]
Examples
Basic usage with bundled dependencies:
import { defineConfig } from "vite";
import { dtsComplex } from "@nhtio/vite-plugins/dts_complex";
export default defineConfig({
build: {
lib: {
entry: "./src/index.ts",
name: "MyLibrary",
},
},
plugins: [
dtsComplex({
bundledDependencies: ["lodash-es", "date-fns"],
}),
],
});Advanced usage with pre-rolled dependencies:
import { defineConfig } from "vite";
import { dtsComplex } from "@nhtio/vite-plugins/dts_complex";
export default defineConfig({
build: {
lib: {
entry: {
index: "./src/index.ts",
utils: "./src/utils/index.ts",
},
name: "MyLibrary",
},
},
plugins: [
dtsComplex({
// Dependencies that need rollup
bundledDependencies: ["lodash-es"],
// Dependencies with pre-existing single declaration files
preRolledDependencies: ["@nhtio/encoder"],
// Custom paths
tsConfigJsonPath: "./tsconfig.build.json",
packageJsonPath: "./package.json",
}),
],
});With regex patterns for scoped packages:
dtsComplex({
bundledDependencies: [
/^@mycompany//, // All @mycompany/* packages
'specific-lib'
],
preRolledDependencies: [
/^@types// // All @types/* packages (usually pre-rolled)
]
})