unplugin-dts-bundle-generator
v3.3.0
Published
DTS bundle generator for Unplugin
Downloads
1,405
Maintainers
Readme
DTS Bundle Generator Unplugin
Ever wanted to easily package your typescript library with a bundled declaration file? Integrate DTS Bundle Generator within your favourite bundler thanks to Unplugin!
(see available bundlers below)
Installation
npm i --save-dev unplugin-dts-bundle-generatoryarn add --dev unplugin-dts-bundle-generatorUsage
Only those bundlers are supported at the moment:
With ESBuild, add this block when calling esbuild.build():
import * as esbuild from 'esbuild';
import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rollup';
await esbuild.build({
plugins: [
dtsBundleGenerator({
outfile: 'my-lib.d.ts',
output: {
// output config
},
libraries: {
// libraries config
},
compilation: {
// compilation options
}
}),
],
entryPoints: 'src/index.ts',
outfile: 'my-lib.js',
format: 'esm',
bundle: true,
});With Rolldown, add this block to your rolldown.config.ts:
import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rolldown';
export default {
plugins: [
dtsBundleGenerator({
file: 'my-lib.d.ts',
output: {
// output config
},
libraries: {
// libraries config
},
compilation: {
// compilation options
}
}),
],
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'es',
},
};With Rollup, add this block to your rollup.config.ts:
import dtsBundleGenerator from 'unplugin-dts-bundle-generator/rollup';
export default {
plugins: [
dtsBundleGenerator({
file: 'my-lib.d.ts',
output: {
// output config
},
libraries: {
// libraries config
},
compilation: {
// compilation options
}
}),
],
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'es',
},
};With Vite, add this block to your vite.config.ts:
import path from 'node:path';
import dtsBundleGenerator from 'unplugin-dts-bundle-generator/vite';
import { defineConfig, normalizePath } from 'vite';
export default defineConfig({
plugins: [
dtsBundleGenerator({
fileName: 'my-lib.d.ts',
output: {
// output config
},
libraries: {
// libraries config
},
compilation: {
// compilation options
}
})
],
build: {
lib: {
entry: normalizePath('src/index.ts'),
formats: ['es'],
fileName: 'my-lib.js'
}
}
});⚠️ Be careful! Plugin options may vary depending on the bundler you are using.
Feel free to open a PR or an issue if you need another export and want to speed up the process, so we can work it out.
Configuration
This library handle both single and multiple entrypoints. You can use any of the output, libraries and compilation options available in the config file of DTS Bundle Generator.
