Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nitedani committed Aug 11, 2024
1 parent c5ad120 commit 7e92915
Show file tree
Hide file tree
Showing 17 changed files with 538 additions and 52 deletions.
1 change: 1 addition & 0 deletions examples/hono-react-cf-pages/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/
/dist/
.vercel
.wrangler
2 changes: 1 addition & 1 deletion examples/hono-react-cf-pages/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
plugins: [
react(),
vike({ prerender: true }),
vikeNode({ entry: 'server/node-entry.js', external: ['vike-node/__handler'] }),
vikeNode({ entry: 'server/node-entry.js' }),
pages({
server: {
kind: 'hono',
Expand Down
10 changes: 10 additions & 0 deletions examples/hono-react-vercel-edge/api/edge-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const config = {
runtime: 'edge'
}

// Import the built server entry from dist, so import.meta.env and other Vite features
// are available in server/app.js (Vite already processed this file)
import app from '../dist/server/app.mjs'

export const GET = app.fetch
export const POST = app.fetch
8 changes: 0 additions & 8 deletions examples/hono-react-vercel-edge/api/index.js

This file was deleted.

16 changes: 11 additions & 5 deletions examples/hono-react-vercel-edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
"scripts": {
"dev": "vite dev",
"build": "vite build",
"deploy": "vercel build && vercel",
"prod": "cross-env NODE_ENV=production node dist/server/index.mjs"
},
"dependencies": {
"@hono/node-server": "^1.12.0",
"@vitejs/plugin-react": "^4.3.1",
"cross-env": "^7.0.3",
"hono": "^4.5.5",
"@hono/node-server": "^1.12.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vike": "^0.4.181",
"vike-node": "0.1.9-commit-022aa1c",
"vike-node": "0.1.9-commit-c5ad120",
"vike-react": "^0.4.18",
"vite": "^5.3.5",
"cross-env": "^7.0.3"
"vite": "^5.3.5"
},
"type": "module"
"type": "module",
"devDependencies": {
"@vite-plugin-vercel/vike": "^8.0.0",
"esbuild": "^0.23.0",
"vite-plugin-vercel": "^8.0.0"
}
}
3 changes: 2 additions & 1 deletion examples/hono-react-vercel-edge/pages/+config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import vikeReact from 'vike-react/config'
const config = {
// https://vike.dev/extends
extends: vikeReact,
prerender: false
prerender: false,
stream: false
}
6 changes: 6 additions & 0 deletions examples/hono-react-vercel-edge/server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Hono } from 'hono'
import vike from 'vike-node/hono'

const app = new Hono()
app.use(vike())
export default app
21 changes: 0 additions & 21 deletions examples/hono-react-vercel-edge/server/index.js

This file was deleted.

17 changes: 17 additions & 0 deletions examples/hono-react-vercel-edge/server/node-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { serve } from '@hono/node-server'
import app from './app.js'

startServer()

function startServer() {
const port = process.env.PORT || 3000
serve(
{
fetch: app.fetch,
port: +port,
// Needed for Bun
overrideGlobalObjects: false
},
() => console.log(`Server running at http://localhost:${port}`)
)
}
2 changes: 1 addition & 1 deletion examples/hono-react-vercel-edge/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"rewrites": [
{
"source": "/((?!assets/).*)",
"destination": "/api"
"destination": "/api/edge-ssr"
}
]
}
11 changes: 0 additions & 11 deletions examples/hono-react-vercel-edge/vite.config.js

This file was deleted.

43 changes: 43 additions & 0 deletions examples/hono-react-vercel-edge/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import react from '@vitejs/plugin-react'
import esbuild from 'esbuild'
import { builtinModules } from 'module'
import vikeNode from 'vike-node/plugin'
import vike from 'vike/plugin'
import { UserConfig } from 'vite'

export default {
plugins: [
react(),
vike({ prerender: true }),
vikeNode({ entry: { index: 'server/node-entry.js', app: 'server/app.js' } }),

// TODO: move this into library
{
apply(_, env) {
return env.isSsrBuild && process.env.VERCEL
},
closeBundle() {
esbuild.buildSync({
entryPoints: ['dist/server/app.mjs'],
outfile: 'dist/server/app.mjs',
format: 'esm',
external: [...builtinModules, ...builtinModules.map((m) => `node:${m}`)],
bundle: true,
target: 'es2022',
logLevel: 'info',
logOverride: {
'ignored-bare-import': 'verbose',
'require-resolve-not-external': 'verbose'
},
minify: false,
allowOverwrite: true,
define: {
'process.env.NODE_ENV': '"production"',
'import.meta.env.NODE_ENV': '"production"'
},
conditions: ['edge-light', 'worker', 'browser', 'module', 'import', 'require']
})
}
}
]
} as UserConfig
3 changes: 2 additions & 1 deletion packages/vike-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"workerd": "./dist/runtime/handler-web-only.js",
"deno": "./dist/runtime/handler-web-only.js",
"browser": "./dist/runtime/handler-web-only.js",
"import": "./dist/runtime/handler-web-and-node.js",
"edge": "./dist/runtime/handler-web-only.js",
"default": "./dist/runtime/handler-web-and-node.js",
"types": "./dist/runtime/handler-web-only.d.ts"
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vike-node/src/plugin/plugins/commonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function commonConfig(configVikeNodePlugin: ConfigVikeNodePlugin): Plugin {

if (typeof config.ssr.external !== 'boolean') {
config.ssr.external ??= []
config.ssr.external.push(...resolvedConfig.server.external)
config.ssr.external.push(...resolvedConfig.server.external, 'vike-node/__handler')
}
config.optimizeDeps.exclude ??= []
config.optimizeDeps.exclude.push(...resolvedConfig.server.external)
Expand Down
2 changes: 1 addition & 1 deletion packages/vike-node/src/plugin/plugins/standalonePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function standalonePlugin(): Plugin {
platform: 'node',
format: 'esm',
bundle: true,
external: configResolvedVike.server.external.filter((id) => id !== 'vike-node/__handler'),
external: configResolvedVike.server.external,
entryPoints: rollupEntryFilePaths,
sourcemap: configResolved.build.sourcemap === 'hidden' ? true : configResolved.build.sourcemap,
outExtension: { '.js': '.mjs' },
Expand Down
2 changes: 1 addition & 1 deletion packages/vike-node/src/plugin/utils/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { unique } from './unique.js'

export { resolveConfig }

export const nativeDependecies = ['sharp', '@prisma/client', '@node-rs/*', 'vike-node/*']
export const nativeDependecies = ['sharp', '@prisma/client', '@node-rs/*']

function resolveConfig(configVike: ConfigVikeNode): ConfigVikeNodeResolved {
if (typeof configVike.server === 'object') {
Expand Down
Loading

0 comments on commit 7e92915

Please sign in to comment.