esbuild-isolated-dts v0.1.1
esbuild-isolated-dts
⚡ Generate declaration files (.d.ts) and declaration maps (.d.ts.map) much faster than tsc.
Prerequisites
Your project must meet these requirements:
- Have typescript 5.5+ installed - uses
transpileDeclarationAPI from TypeScript. - Have
isolatedDeclarationsset to true intsconfig.json. - Follow the isolated declarations rule.
Install
# npm
npm install esbuild-isolated-dts --save-dev
# pnpm
pnpm install esbuild-isolated-dts --save-dev
# yarn
yarn add esbuild-isolated-dts --save-devUsage
To generate .d.ts and .d.ts.map files together with transpiling entire directory to .js simply do the following, declaration maps are generated by default:
import * as esbuild from 'esbuild';
import { isoldatedDtsPlugin } from 'esbuild-isolated-dts';
await esbuild.build({
entryPoints: ['src/**/*.ts'],
format: 'esm',
target: 'es2017',
outdir: 'dist',
plugins: [isoldatedDtsPlugin()],
});Options
outdir
- Type:
string - Default:
process.cwd()
Overrides outdir in esbuild config for outputting type declaration. Allows outputting type declarations to a different directory.
Note: If outfile in esbuild config is used, outdir overrides the directory part of outfile.
transpileOptions
- Type:
typescript.TranspileOptions | undefined - Default:
undefined
Typescript configuration. For example you can turn off outputting declaration maps like this:
import * as esbuild from 'esbuild';
import { isoldatedDtsPlugin } from 'esbuild-isolated-dts';
await esbuild.build({
entryPoints: ['src/**/*.ts'],
format: 'esm',
target: 'es2017',
outdir: 'dist',
plugins: [
isoldatedDtsPlugin({
transpileOptions: {
compilerOptions: {
declarationMap: false,
},
},
}),
],
});Note: rootDir and outDir can't be directly modified, because these fields are necessary for correct declaration map output.
exts
- Type:
string[] - Default:
['ts', 'tsx']
Generate declarations only for files with the extension in exts.
dryRun
- Type:
boolean - Default:
false
Doesn't ouput any files, useful together with logLevel: 'debug'
logLevel
- Type:
'debug' | 'silent' - Default:
'silent'
Outputs extra information when set to 'debug'
Credits
Inspired by/alternative: unplugin-isolated-decl
Licence
MIT