Detalhes do pacote

bun-plugin-auto-imports

stacksjs797MIT0.3.1

A Bun Bundler plugin that allows for auto-imports.

auto-imports, bun, plugin, unimport

readme (leia-me)

Social Card of Bun Plugin Auto Imports

npm version GitHub Actions Commitizen friendly npm downloads

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-imports

You 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, AutoImportsOptions proxies UnimportOptions.

Testing

bun test

Changelog

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:

Discussions on GitHub

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 💙

changelog (log de mudanças)

Changelog

v0.3.0...main

compare changes

🩹 Fixes

🏡 Chore

❤️ Contributors

v0.2.2...main

compare changes

🚀 Enhancements

  • Add support for dirs option (9faf6ba)

🏡 Chore

❤️ Contributors

v0.2.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.2.0...main

compare changes

🏡 Chore

  • Slightly update structure (3ccbaf3)

❤️ Contributors

v0.1.5...main

compare changes

🚀 Enhancements

❤️ Contributors

v0.1.4...main

compare changes

🩹 Fixes

  • Adjust AutoImportsOptions type (4d355a1)

❤️ Contributors

v0.1.3...main

compare changes

🏡 Chore

❤️ Contributors

v0.1.2...main

compare changes

🏡 Chore

❤️ Contributors

v0.1.1...main

compare changes

🏡 Chore

❤️ Contributors

v0.1.0...main

compare changes

🏡 Chore

  • Use dtsx to generate dts (d791c84)

❤️ Contributors