feat(ssr): add server entrypoint#164
Conversation
Add an optional `server` plugin option that bundles a custom server entry into `dist/server` instead of the default renderer bundle. The server imports the renderer through a new typed `virtual:app-renderer` ambient module, and `RenderData.statusCode` is narrowed to a `ResponseStatusCode` literal union. The event-board examples adopt the new entrypoint via `src/server.ts`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #164 +/- ##
=======================================
Coverage 83.86% 83.86%
=======================================
Files 138 138
Lines 2968 2968
Branches 560 560
=======================================
Hits 2489 2489
Misses 340 340
Partials 139 139 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds an optional server entrypoint to the @nano_kit/ssr Vite plugin, enabling production SSR builds to emit a bundled server output (dist/server) that can import the configured renderer via a new virtual:app-renderer module, while keeping the default renderer build behavior unchanged when server is not provided.
Changes:
- Extend the SSR Vite plugin with
server/serverDiroptions andvirtual:app-rendererresolution, and adjust SSR build output routing. - Ship an ambient
virtual:app-renderertype declaration and narrow rendererstatusCodetyping to aResponseStatusCodeliteral union. - Update event-board examples to build/run via
dist/server/index.js, usevirtual:app-renderer, and simplify the API factory toapi().
Reviewed changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ssr/test/app/server.js | Adds a server entry fixture importing virtual:app-renderer for server-build tests. |
| packages/ssr/src/vite-plugin/virtual.d.ts | Introduces ambient typing for the virtual:app-renderer module. |
| packages/ssr/src/vite-plugin/index.spec.ts | Adds a new vitest case covering server entry bundling with virtual:app-renderer. |
| packages/ssr/src/vite-plugin/index.js | Implements server/serverDir handling and virtual module resolution for server builds. |
| packages/ssr/src/vite-plugin/index.d.ts | Updates plugin option types to include server and serverDir and pulls in virtual typings. |
| packages/ssr/src/renderer/utils.ts | Tightens status/redirect helper return types and uses ResponseStatusCode in responseStatus. |
| packages/ssr/src/renderer/renderer.types.ts | Defines ResponseStatusCode and narrows RenderData.statusCode to it. |
| packages/ssr/package.json | Adjusts build script to ship additional .d.ts files for the plugin. |
| examples/event-board/svelte-nano_kit-ssr/vite.config.ts | Configures SSR bundling for build and provides server entry to the SSR plugin. |
| examples/event-board/svelte-nano_kit-ssr/src/server.ts | Switches prod server to virtual:app-renderer and updates API mounting. |
| examples/event-board/svelte-nano_kit-ssr/package.json | Runs preview/start from dist/server/index.js. |
| examples/event-board/svelte-nano_kit-ssr/api/server.js | Updates API server mounting to align with api() returning a Hono app. |
| examples/event-board/svelte-nano_kit-ssr/api/index.js | Renames createApiApp to api and removes the old wrapper. |
| examples/event-board/react-nano_kit-intl-ssr/vite.config.ts | Configures SSR bundling for build and provides server entry to the SSR plugin. |
| examples/event-board/react-nano_kit-intl-ssr/src/server.ts | Switches prod server to virtual:app-renderer and updates API mounting. |
| examples/event-board/react-nano_kit-intl-ssr/package.json | Runs preview/start from dist/server/index.js. |
| examples/event-board/react-nano_kit-intl-ssr/api/server.js | Updates API server mounting to align with api() returning a Hono app. |
| examples/event-board/react-nano_kit-intl-ssr/api/index.js | Renames createApiApp to api and removes the old wrapper. |
| examples/event-board/preact-nano_kit-intl-ssr/vite.config.ts | Configures SSR bundling for build and provides server entry to the SSR plugin. |
| examples/event-board/preact-nano_kit-intl-ssr/src/server.ts | Switches prod server to virtual:app-renderer and updates API mounting. |
| examples/event-board/preact-nano_kit-intl-ssr/package.json | Runs preview/start from dist/server/index.js. |
| examples/event-board/preact-nano_kit-intl-ssr/api/server.js | Updates API server mounting to align with api() returning a Hono app. |
| examples/event-board/preact-nano_kit-intl-ssr/api/index.js | Renames createApiApp to api and removes the old wrapper. |
| examples/event-board/common/api/server.js | Updates common API server mounting to align with api() returning a Hono app. |
| examples/event-board/common/api/index.js | Renames createApiApp to api and removes the old wrapper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Adds an optional
serverentrypoint to@nano_kit/ssr, alongside the existingclientandrenderer.When the
serverplugin option is set, that file is bundled intodist/server(instead of emitting the default renderer bundle) and receives the renderer through a new typedvirtual:app-renderermodule. Default behaviour is unchanged — withoutserver, the renderer bundle is still produced.Changes
@nano_kit/ssrvite-plugin:server/serverDiroptions,virtual:app-rendererresolution, and an SSR build branch that emits the server bundle.virtual:app-rendererdeclaration (shipped scriptvirtual.d.tspulled in fromindex.d.ts);RenderData.statusCodenarrowed to aResponseStatusCodeliteral union.src/server.tsimportingvirtual:app-renderer; server build bundles deps viassr.noExternal(gated tobuild, so dev still loads the renderer through Vite's SSR module runner); api factory renamed toapi.Testing
packages/ssr: oxlint + vitest (incl. new server-build test) + tsc — green.dist/server+dist/client; prod server (SSR + bundled api + static with cache headers) and dev (SSR middleware + api plugin) verified at runtime.🤖 Generated with Claude Code