Add bun and netlify-edge builds
Little plugins to support netlify edge and bun builds.
🦋 Changeset detected
Latest commit: d65592e348eec7b657b6749f0652943f60fafcda
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
| Name | Type |
|---|---|
| @hono/vite-bun | Major |
| @hono/vite-netlify | Major |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
@chtibizoux
Thanks. I'll review this later!
@chtibizoux is this ready for reviewing?
Yes, it's working now !
Hi @chtibizoux
There is something I want to ask you.
First, is the @hono/vite-bun necessary? This means that to run your application on production, do you need to build the app to server.js? I'm unfamiliar with deploying the Bun app, but I think running the src/index.ts directly with the bun command is okay. What do you think?
Secode, building @hono/vite-netlify fails:
Can you check it?
For Bun build, yes it's necessary to build the app with vite because if you use vite specific code like in HonoX, you can't run it with only Bun directly and static assets in public folder aren't served directly by HonoX to.
I planned to create a similar plugin for node.js because the same problem occurs.
And for Netlify build, I have the same bug when I build it and I don't know why, but I solved it by adding node in compilerOptions.types in packages/netlify/tsconfig.json like this :
{
"extends": "../../tsconfig.base.json",
"include": [
"src",
"test"
],
"compilerOptions": {
"module": "ES2022",
"target": "ES2022",
"types": [
"vite/client",
"node"
]
},
}
Which is weird because it's already there in tsconfig.base.json and bun and cloudflare-pages have the same config and import but don't throw any error.
Hi @chtibizoux
Regarding this PR, I would like to pass on merging @hono/vite-bun.
- If your app does not use a Vite specific feature, you can run your app with the
buncommand. - You can build your HonoX app by setting the
vite.config.tsproperly without this plugin. I don't think we need to create a plugin.
If you want to run build for bun, set up the vite.config.ts:
// vite.config.ts
import honox from 'honox/vite'
import { defineConfig } from 'vite'
export default defineConfig(({ mode }) => {
if (mode === 'client') {
return {
plugins: [honox()]
}
} else {
return {
build: {
ssr: true,
emptyOutDir: false,
rollupOptions: {
external: [/^node:/],
input: './entry.ts',
output: {
entryFileNames: 'server.js'
}
}
},
plugins: [honox()]
}
}
})
entry.ts is below:
// entry.ts
import { createApp } from 'honox/server'
import { serveStatic } from 'hono/bun'
const app = createApp({
init: (app) => {
app.use(
'/static/*',
serveStatic({
root: './dist'
})
)
}
})
export default app
The build command is:
vite build --mode client && vite build
But, we may merge the plugin for Netlify. Thanks.
I use Bun currently for local development; seems compatible locally without this patch. Though I do welcome the attention; maybe mentioning in docs that this repo is Bun-compatible?
I'm interested in the Netlify Functions (non-edge) support here!
@yusukebe @chtibizoux I noticed the codebase has changed a lot since this PR was proposed, so I rebuilt the netlify-functions adapter (since that is what I needed) using the current codebase's build package. See #218