Skip to content

Commit

Permalink
feat(vite-dev-server): use vite runtime API (#129)
Browse files Browse the repository at this point in the history
* feat: use vite runtime API

* chore: formatting

* chore: added changeset

* chore: readme changes
  • Loading branch information
alessandrojcm authored Apr 25, 2024
1 parent 5b728da commit b4019f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-houses-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hono/vite-dev-server": minor
---

Switched to executeEntrypoint instead of ssrLoadModule
2 changes: 1 addition & 1 deletion packages/dev-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can develop your application with Vite. It's fast.
- Support any `fetch`-based applications.
- Hono applications run on.
- Fast by Vite.
- HMR (Only for the client side. [Currently, Vite doesn't support HMR for SSR](https://github.com/vitejs/vite/issues/7887)).
- HMR
- Plugins are available, e.g., Cloudflare Pages.
- Also runs on Bun.

Expand Down
7 changes: 5 additions & 2 deletions packages/dev-server/src/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type http from 'http'
import { getRequestListener } from '@hono/node-server'
import { minimatch } from 'minimatch'
import type { Plugin as VitePlugin, ViteDevServer, Connect } from 'vite'
import { createViteRuntime } from 'vite'
import type { ViteRuntime } from 'vite/runtime'
import { getEnv as cloudflarePagesGetEnv } from './cloudflare-pages/index.js'
import type { Env, Fetch, EnvFunc, Plugin, Adapter } from './types.js'

Expand Down Expand Up @@ -70,6 +72,7 @@ export const defaultOptions: Required<Omit<DevServerOptions, 'env' | 'cf' | 'ada

export function devServer(options?: DevServerOptions): VitePlugin {
const entry = options?.entry ?? defaultOptions.entry
let runtime: ViteRuntime
const plugin: VitePlugin = {
name: '@hono/vite-dev-server',
configureServer: async (server) => {
Expand All @@ -92,11 +95,11 @@ export function devServer(options?: DevServerOptions): VitePlugin {
}
}
}

runtime ??= await createViteRuntime(server)
let appModule

try {
appModule = await server.ssrLoadModule(entry)
appModule = await runtime.executeEntrypoint(entry)
} catch (e) {
return next(e)
}
Expand Down

0 comments on commit b4019f0

Please sign in to comment.