undts Svelte Themes

Undts

💥 Crazy d.ts files generator, supports .vue, .svelte, .astro, .vine.ts files✨

undts

Crazy d.ts files generator💥Supports multiple template languages!

English | 简体中文

What files can it bundle to become d.ts?

  • Normal .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 ⚡️

Full documentation

Please see the documentation.

Quick Start

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'
})

Using with frameworks

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.

Using with Vite Lib mode(Recommended)
// 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()
  ],
})
Using with Rollup + SWC
// 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(),
  ],
})
Using with tsup(it powered by esbuild)
// 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(),
  ],
})

License & Author

Naily Zero & MIT

Top categories

Loading Svelte Themes