Vite Reference
Generated from src/vite/index.ts.
| Export | Kind | Source | Description |
|---|---|---|---|
snapshotSsr | function | src/vite/index.ts | Vite plugin for SSR builds with Snapshot. When added to the Vite config, it: 1. Enables Vite’s manifest output (build.manifest: true) for client builds so that slingshot-ssr can inject hashed asset URLs into the SSR HTML. 2. Configures the server bundle output directory when vite build --ssr is run. 3. Generates dist/client/prefetch-manifest.json after the client build, mapping URL patterns to JS chunk and CSS file URLs for <PrefetchLink> prefetching. Two build commands are required: - vite build → client bundle in dist/client/ + .vite/manifest.json - vite build --ssr → server bundle in dist/server/ Add both to your package.json: json { "scripts": { "build:client": "vite build", "build:server": "vite build --ssr src/ssr/entry-server.ts", "build": "bun run build:client && bun run build:server" } } |
SnapshotSsrOptions | interface | src/vite/index.ts | Options for the snapshotSsr() Vite plugin. |
snapshotSync | function | src/vite/index.ts | Vite plugin that runs Snapshot’s OpenAPI sync step during the Vite lifecycle. Use this when a frontend project should regenerate API types and hooks from a Slingshot schema file or backend endpoint at startup. |
SnapshotSyncOptions | interface | src/vite/index.ts | Options for snapshotSync(), Snapshot’s Vite-driven Slingshot sync plugin. |
staticParamsPlugin | function | src/vite/index.ts | Vite plugin that scans the server routes directory for generateStaticParams exports at build time and writes static-params.json to the client output directory. static-params.json is a build-time artifact consumed by the ISR pre-renderer and by deployment tooling. It maps route patterns to their enumerated param sets. This plugin runs during the buildEnd hook and only fires for client builds (not the SSR bundle build). It is automatically included in the plugin array returned by snapshotSsr() — you do not need to add it manually. |
Details
Section titled “Details”snapshotSsr(opts?: SnapshotSsrOptions) => Plugin<any>[]
Section titled “snapshotSsr(opts?: SnapshotSsrOptions) => Plugin<any>[]”Vite plugin for SSR builds with Snapshot.
When added to the Vite config, it:
- Enables Vite’s manifest output (
build.manifest: true) for client builds so that slingshot-ssr can inject hashed asset URLs into the SSR HTML. - Configures the server bundle output directory when
vite build --ssris run. - Generates
dist/client/prefetch-manifest.jsonafter the client build, mapping URL patterns to JS chunk and CSS file URLs for<PrefetchLink>prefetching.
Two build commands are required:
vite build→ client bundle indist/client/+.vite/manifest.jsonvite build --ssr→ server bundle indist/server/
Add both to your package.json:
{ "scripts": { "build:client": "vite build", "build:server": "vite build --ssr src/ssr/entry-server.ts", "build": "bun run build:client && bun run build:server" }}Parameters:
| Name | Description |
|---|---|
opts | Optional configuration. All fields have defaults. |
Returns: A Vite Plugin object.
Example:
import { defineConfig } from 'vite'import react from '@vitejs/plugin-react'import { snapshotSync, snapshotSsr } from '@lastshotlabs/snapshot/vite'
export default defineConfig({ plugins: [ react(), snapshotSync({ file: './openapi.json' }), snapshotSsr(), ],})snapshotSync(opts?: SnapshotSyncOptions) => Plugin<any>
Section titled “snapshotSync(opts?: SnapshotSyncOptions) => Plugin<any>”Vite plugin that runs Snapshot’s OpenAPI sync step during the Vite lifecycle.
Use this when a frontend project should regenerate API types and hooks from a Slingshot schema file or backend endpoint at startup.
Parameters:
| Name | Description |
|---|---|
opts | Sync source and generation options |
Returns: A Vite plugin that invokes Snapshot sync at build start
staticParamsPlugin(opts: StaticParamsPluginOptions) => Plugin<any>
Section titled “staticParamsPlugin(opts: StaticParamsPluginOptions) => Plugin<any>”Vite plugin that scans the server routes directory for generateStaticParams
exports at build time and writes static-params.json to the client output
directory.
static-params.json is a build-time artifact consumed by the ISR pre-renderer
and by deployment tooling. It maps route patterns to their enumerated param sets.
This plugin runs during the buildEnd hook and only fires for client builds
(not the SSR bundle build). It is automatically included in the plugin array
returned by snapshotSsr() — you do not need to add it manually.
Parameters:
| Name | Description |
|---|---|
opts | Plugin configuration. |
Returns: A Vite Plugin object.
Example:
Standalone usage (if needed outside snapshotSsr)```tsimport { staticParamsPlugin } from '@lastshotlabs/snapshot/vite'
// vite.config.tsexport default defineConfig({plugins: [staticParamsPlugin({ clientOutDir: 'dist/client' })],})---