diff --git a/package.json b/package.json index e30870e4a..79a538d46 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "examples:prd:24_nesting": "NAME=24_nesting pnpm run examples:prd", "website:dev": "(cd packages/website && pnpm run dev)", "website:build": "cd packages/website && pnpm run build", - "website:vercel": "pnpm run compile && pnpm run website:build && mv packages/website/.vercel/output .vercel/", + "website:vercel": "pnpm run compile && pnpm run website:build --with-vercel-static && mv packages/website/.vercel/output .vercel/", "website:prd": "pnpm run website:build && (cd packages/website && pnpm start)" }, "prettier": { diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts index 64ecb137d..741154083 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-cloudflare.ts @@ -17,16 +17,21 @@ import { DIST_ENTRIES_JS, DIST_PUBLIC } from '../builder/constants.js'; const SERVE_JS = 'serve-cloudflare.js'; const getServeJsContent = (srcEntriesFile: string) => ` -import { runner, importHono, importHonoContextStorage } from 'waku/unstable_hono'; +import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const { contextStorage } = await importHonoContextStorage(); +let contextStorage; +try { + ({ contextStorage } = await import('hono/context-storage')); +} catch {} const loadEntries = () => import('${srcEntriesFile}'); let serveWaku; const app = new Hono(); -app.use(contextStorage()); +if (contextStorage) { + app.use(contextStorage()); +} app.use('*', (c, next) => serveWaku(c, next)); app.notFound(async (c) => { const assetsFetcher = c.env.ASSETS; @@ -118,6 +123,9 @@ export function deployCloudflarePlugin(opts: { if (id === `${opts.srcDir}/${SERVE_JS}`) { return getServeJsContent(entriesFile); } + if (id === 'hono/context-storage') { + return ''; + } }, closeBundle() { const { deploy, unstable_phase } = platformObject.buildOptions || {}; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts index c915ee701..47255d9e0 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-netlify.ts @@ -9,15 +9,20 @@ import { DIST_PUBLIC } from '../builder/constants.js'; const SERVE_JS = 'serve-netlify.js'; const getServeJsContent = (srcEntriesFile: string) => ` -import { runner, importHono, importHonoContextStorage } from 'waku/unstable_hono'; +import { runner, importHono } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const { contextStorage } = await importHonoContextStorage(); +let contextStorage; +try { + ({ contextStorage } = await import('hono/context-storage')); +} catch {} const loadEntries = () => import('${srcEntriesFile}'); const app = new Hono(); -app.use(contextStorage()); +if (contextStorage) { + app.use(contextStorage()); +} app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound((c) => { const notFoundHtml = globalThis.__WAKU_NOT_FOUND_HTML__; @@ -66,6 +71,9 @@ export function deployNetlifyPlugin(opts: { if (id === `${opts.srcDir}/${SERVE_JS}`) { return getServeJsContent(entriesFile); } + if (id === 'hono/context-storage') { + return ''; + } }, closeBundle() { const { deploy, unstable_phase } = platformObject.buildOptions || {}; diff --git a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts index 3e6f51f9f..47d3e3519 100644 --- a/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts +++ b/packages/waku/src/lib/plugins/vite-plugin-deploy-vercel.ts @@ -15,18 +15,23 @@ const getServeJsContent = ( ) => ` import path from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; -import { runner, importHono, importHonoContextStorage, importHonoNodeServer } from 'waku/unstable_hono'; +import { runner, importHono, importHonoNodeServer } from 'waku/unstable_hono'; const { Hono } = await importHono(); -const { contextStorage } = await importHonoContextStorage(); const { getRequestListener } = await importHonoNodeServer(); +let contextStorage; +try { + ({ contextStorage } = await import('hono/context-storage')); +} catch {} const distDir = '${distDir}'; const publicDir = '${distPublic}'; const loadEntries = () => import('${srcEntriesFile}'); const app = new Hono(); -app.use(contextStorage()); +if (contextStorage) { + app.use(contextStorage()); +} app.use('*', runner({ cmd: 'start', loadEntries, env: process.env })); app.notFound((c) => { // FIXME better implementation using node stream? @@ -78,6 +83,9 @@ export function deployVercelPlugin(opts: { if (id === `${opts.srcDir}/${SERVE_JS}`) { return getServeJsContent(opts.distDir, DIST_PUBLIC, entriesFile); } + if (id === 'hono/context-storage') { + return ''; + } }, closeBundle() { const { deploy, unstable_phase } = platformObject.buildOptions || {}; diff --git a/packages/waku/src/unstable_hono.ts b/packages/waku/src/unstable_hono.ts index 197c8fb46..c1e3292da 100644 --- a/packages/waku/src/unstable_hono.ts +++ b/packages/waku/src/unstable_hono.ts @@ -3,7 +3,6 @@ export { runner } from './lib/hono/runner.js'; export const importHono = () => import('hono'); -export const importHonoContextStorage = () => import('hono/context-storage'); export const importHonoNodeServer: any = () => import('@hono/node-server'); export const importHonoNodeServerServeStatic = () => import('@hono/node-server/serve-static');