stacks/bun-plugin-auto-imports
publicClone
Push over the same URL. A password will not work: create a token under access tokens and use it in place of one.
- .config
- .github
- .vscode
- docs
- src
- test
- .editorconfig 147 B
- .gitattributes 38 B
- .gitignore 107 B
- build.ts 424 B
- bun.lock 40.4 KB
- bunfig.toml 107 B
- CHANGELOG.md 22.9 KB
- CLAUDE.md 1.4 KB
- deps.yaml 32 B
- LICENSE.md 1.1 KB
- package.json 2.3 KB
- pantry.lock 261 B
- README.md 4.1 KB
- test.ts 491 B
- tsconfig.json 631 B

bun-plugin-auto-imports
This Bun plugin allows for support of auto-imports in your server-side code.
Features
- Auto-imports support for Bun
Usage
bun install -d bun-plugin-auto-importsYou may now use the plugin:
// 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:
// 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,AutoImportsOptionsproxiesUnimportOptions.
Testing
bun testChangelog
Please see our releases page for more information on what has changed recently.
Contributing
Please review the Contributing Guide for details.
Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
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.
Credits
Many thanks to the following core technologies & people who have contributed to this package:
License
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙
[codecov-href]: https://codecov.io/gh/stacksjs/bun-plugin-auto-imports -->