d.ts
?.ts
, .tsx
files.vue
files, using @vue/compiler-sfc
.svelte
files, using svelte2tsx
.astro
files, using @astrojs/compiler
.vine.ts
files, using @vue-vine/compiler
All special files can be disabled by options, just set like vue: false
, svelte: false
, etc.
I will keep the configuration as simple as possible, just like tsup ⚡️
Please see the documentation.
pnpm install undts
Create a file in your project root directory:
import { build } from 'undts'
build({
entry: [
// Add your entry files here
'./src/index.ts'
],
// ... more options, you can see jsdoc in the source code
})
Then run this file with node
/tsx
/ts-node
, for example:
pnpx tsx your-file.ts
It will generate d.ts file in dist
directory by default. You can change the output directory by outDir
option:
build({
entry: ['./src/index.ts'],
outDir: './types', // default is './dist'
})
Thanks to the powerful unplugin
, undts can be used in combination with vite
/rollup
/esbuild
with zero configuration, it will automatically using the vite
/rollup
/esbuild
configuration file's entry
/input
option as the entry
option of undts
.
// vite.config.ts
import undts from 'undts/vite'
import { defineConfig } from 'vite'
export default defineConfig({
build: {
lib: {
// undts will automatically use this entry, you don't need to set it again in plugin options
entry: 'src/index.ts',
},
},
plugins: [
undts()
],
})
// rollup.config.mjs
import swc from '@rollup/plugin-swc'
import { defineConfig } from 'rollup'
import undts from 'undts/rollup'
export default defineConfig({
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'es',
},
plugins: [
swc(),
// It will automatically use input option as the entry option of undts
undts(),
],
})
// tsup.config.ts
import { defineConfig } from 'tsup'
import undts from 'undts/esbuild'
export default defineConfig({
entry: ['src/index.ts'],
// Disable tsup's default dts generation, use undts instead
dts: false,
sourcemap: true,
esbuildPlugins: [
// It will automatically use entry option as the entry option of undts
undts(),
],
})
Naily Zero & MIT