honojs / vite-plugins

Vite Plugins for Hono
https://hono.dev
134 stars 35 forks source link

feat: add `export` option #86

Closed jxom closed 9 months ago

jxom commented 9 months ago

Would be nice if there were a way to configure the export name. This would be useful to avoid conflict in cases where some runtimes (ie. Vercel Serverless) also rely on a default export.

e.g.

// ./api/index.ts

import { Hono } from 'hono'
import { handle } from 'hono/vercel'

export const runtime = 'edge';

export const app = new Hono().basePath('/api')

app.get('/hello', (c) => {
  return c.json({
    message: 'Hello Vercel!',
  })
})

export const GET = handle(app)
export const POST = handle(app)
// ./vite.config.ts
import devServer from '@hono/vite-dev-server'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    devServer({
      entry: './api/index.ts',
      export: 'app'
    }),
  ]
})
changeset-bot[bot] commented 9 months ago

🦋 Changeset detected

Latest commit: 4e2c131018a233df2c615d41f003fb059fd02a53

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | --------------------- | ----- | | @hono/vite-dev-server | Minor |

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 commented 9 months ago

Hi @jxom !

This is an interesting option! I'd like to merge this PR.

Please do the Two things:

  1. Run yarn changeset to add a changeset. This will be a feat change.
  2. Update the README. Add the option to these lines.

Thanks!

jxom commented 9 months ago

Done!

yusukebe commented 9 months ago

@jxom

Thanks! Merge now!