Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bun and netlify-edge builds #143

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

chtibizoux
Copy link

Little plugins to support netlify edge and bun builds.

Copy link

changeset-bot bot commented Jun 13, 2024

🦋 Changeset detected

Latest commit: 5854ef7

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

@yusukebe
Copy link
Member

@chtibizoux

Thanks. I'll review this later!

@yusukebe
Copy link
Member

@chtibizoux is this ready for reviewing?

@chtibizoux
Copy link
Author

Yes, it's working now !

@yusukebe
Copy link
Member

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:

CleanShot 2024-06-18 at 15 30 40@2x

Can you check it?

@chtibizoux
Copy link
Author

chtibizoux commented Jun 18, 2024

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.
HonoX error
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.

@yusukebe
Copy link
Member

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 bun command.
  • You can build your HonoX app by setting the vite.config.ts properly 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.

@tomByrer
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants