honojs-middleware/packages/bun-transpiler
floriankapaun b6e59dd19c
fix(bun-transpiler): Apply headers when using serveStatic; Improvement: Make options optional; (#349)
*  Add failing serveStatic test (headers not applied)

* 🐛 Fix: Apply headers when using serveStatic

* 🚸 Make options optional

* 🔖 Add changeset

* ✏️ Fix naming in comment

* 🚸 Export defaultOptions

* 🏷️ Improve Typing of defaultOptions
2024-01-12 05:03:13 +09:00
..
src fix(bun-transpiler): Apply headers when using serveStatic; Improvement: Make options optional; (#349) 2024-01-12 05:03:13 +09:00
CHANGELOG.md Version Packages (#347) 2024-01-08 07:40:41 +09:00
README.md Add Bun Transpiler middleware #344 (#345) 2024-01-08 07:03:56 +09:00
package.json Version Packages (#347) 2024-01-08 07:40:41 +09:00
tsconfig.json Add Bun Transpiler middleware #344 (#345) 2024-01-08 07:03:56 +09:00

README.md

Bun Transpiler middleware for Hono

The Bun Transpiler middleware is a Hono middleware designed to transpile content such as TypeScript or TSX. You can place your script written in TypeScript in a directory and serve it using serveStatic. When you apply this middleware, your script will automatically be served transpiled into JavaScript code.

This middleware works only with Bun.

Usage

Installation

npm i @hono/bun-transpiler

Example

import { Hono } from 'hono'
import { serveStatic } from 'hono/bun'
import { bunTranspiler } from '@hono/bun-transpiler'

const app = new Hono()

app.get('/static/:scriptName{.+.tsx?}', bunTranspiler())
app.get('/static/*', serveStatic({ root: './' }))

export default app

Notes

  • This middleware does not have a cache feature. If you want to cache the transpiled code, use Cache Middleware or your own custom middleware.

Author

Florian Kapaun https://github.com/floriankapaun

Heavily inspired by esbuild-transpiler by Andres C. Rodriguez and Yusuke Wada.

License

MIT