https://github.com/shtse8/bun-plugin-dts
A Bun plugin to automatically generate TypeScript declaration files (.d.ts) during build.
https://github.com/shtse8/bun-plugin-dts
build-tool bun bun-plugin declaration-files dts typescript
Last synced: 4 months ago
JSON representation
A Bun plugin to automatically generate TypeScript declaration files (.d.ts) during build.
- Host: GitHub
- URL: https://github.com/shtse8/bun-plugin-dts
- Owner: shtse8
- License: mit
- Created: 2025-04-02T06:07:19.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-10T03:04:31.000Z (about 1 year ago)
- Last Synced: 2025-10-20T22:42:53.780Z (8 months ago)
- Topics: build-tool, bun, bun-plugin, declaration-files, dts, typescript
- Language: TypeScript
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/funding.yml
- License: LICENSE
Awesome Lists containing this project
README
# @shtse8/bun-plugin-dts
[](https://badge.fury.io/js/%40shtse8%2Fbun-plugin-dts)
[](https://github.com/shtse8/bun-plugin-dts/actions/workflows/publish.yml)
A plugin for [Bun](https://bun.sh) that generates TypeScript declaration files
(`.d.ts`) during the `bun build` process.
## Problem
Bun's built-in bundler (`bun build`) is incredibly fast, but it currently does
not generate `.d.ts` files automatically. This makes it difficult to publish
TypeScript libraries built with Bun, as consumers rely on these files for type
checking and autocompletion.
`@shtse8/bun-plugin-dts` solves this by hooking into the build process and using
the TypeScript Compiler API to generate the necessary declaration files
alongside your JavaScript output.
## Installation
```bash
bun add --dev @shtse8/bun-plugin-dts
```
You also need `typescript` installed, which is likely already in your project:
```bash
bun add --dev typescript
```
## Usage
Import the plugin and add it to the `plugins` array in your `Bun.build`
configuration.
**Example `build.ts`:**
```typescript
import Bun from "bun";
import dts from "@shtse8/bun-plugin-dts"; // Import the plugin
await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
target: "bun", // Or your desired target
plugins: [
dts(), // Add the plugin here
],
// ... other build options
});
console.log("Build complete!");
```
The plugin will automatically:
1. Find your `tsconfig.json` in the project `root`.
2. Read the entry points and output directory (`outdir`) from the `Bun.build`
config.
3. Generate `.d.ts` files corresponding to your entry points within the
specified `outdir`.
## Configuration (Optional)
Currently, the plugin automatically detects settings from your `tsconfig.json`
and `Bun.build` configuration. Explicit plugin options may be added in the
future if needed.
## Contributing
Contributions are welcome! Please feel free to open an issue or submit a pull
request on the [GitHub repository](https://github.com/shtse8/bun-plugin-dts).
## Support
If you find this plugin helpful, consider supporting the development:
[](https://buymeacoffee.com/shtse8)
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
for details.