https://github.com/stacksjs/bun-plugin-auto-imports
Auto Imports support for Bun.
https://github.com/stacksjs/bun-plugin-auto-imports
auto-imports bun bun-plugin
Last synced: over 1 year ago
JSON representation
Auto Imports support for Bun.
- Host: GitHub
- URL: https://github.com/stacksjs/bun-plugin-auto-imports
- Owner: stacksjs
- License: mit
- Created: 2024-10-24T13:39:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-01T11:38:11.000Z (over 1 year ago)
- Last Synced: 2025-03-07T17:26:12.399Z (over 1 year ago)
- Topics: auto-imports, bun, bun-plugin
- Language: TypeScript
- Homepage:
- Size: 409 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README

[![npm version][npm-version-src]][npm-version-href]
[![GitHub Actions][github-actions-src]][github-actions-href]
[](http://commitizen.github.io/cz-cli/)
[![npm downloads][npm-downloads-src]][npm-downloads-href]
This Bun plugin allows for support of auto-imports in your server-side code.
## Features
- Auto-imports support for Bun
## Usage
```bash
bun install -d bun-plugin-auto-imports
```
You may now use the plugin:
```ts
// index.ts
import type { AutoImportsOptions } from 'bun-plugin-auto-imports'
import { plugin } from 'bun'
import { autoImports } from 'bun-plugin-auto-imports'
const options: AutoImportsOptions = {
presets: ['solid-js'], // any unimport presets are valid
imports: [{ name: 'z', from: 'zod' }],
dirs: ['./src'],
dts: `./src/auto-import.d.ts`, // default is `./auto-import.d.ts`
}
plugin(autoImports(options))
Bun.serve({
fetch: handler,
port: 3000,
})
```
In your "server file," you may now use the auto-imported modules:
```ts
// server.ts
// `z` is auto imported from zod
const Body = z.object({
msg: z.string(),
})
export async function handler(req: Request) {
try {
const body = await req.json()
const data = Body.parse(body)
return new Response(`Received: ${data.msg}`)
}
catch (e) {
return new Response('Invalid body', { status: 400 })
}
}
```
> [!NOTE]
> If you are familiar with `unimport`, `AutoImportsOptions` proxies `UnimportOptions`.
## Testing
```bash
bun test
```
## Changelog
Please see our [releases](https://github.com/stacksjs/bun-plugin-auto-imports/releases) page for more information on what has changed recently.
## Contributing
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
## Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
For casual chit-chat with others using this package:
[Join the Stacks Discord Server](https://discord.gg/stacksjs)
## Postcardware
โSoftware that is free, but hopes for a postcard.โ We love receiving postcards from around the world showing where `bun-plugin-auto-imports` is being used! We showcase them on our website too.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States ๐
## Sponsors
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
- [JetBrains](https://www.jetbrains.com/)
- [The Solana Foundation](https://solana.com/)
## Credits
Many thanks to the following core technologies & people who have contributed to this package:
- [unplugin-auto-import](https://github.com/unplugin/unplugin-auto-import)
- [unimport](https://github.com/unjs/unimport)
- [Chris Breuer](https://github.com/chrisbbreuer)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/bun-plugin-auto-imports/tree/main/LICENSE.md) for more information.
Made with ๐
[npm-version-src]:
[npm-version-href]:
[npm-downloads-src]:
[npm-downloads-href]:
[github-actions-src]:
[github-actions-href]: