Skip to content

Vite Reference

Generated from src/vite/index.ts.

ExportKindSourceDescription
snapshotSsrfunctionsrc/vite/index.tsVite 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" } }
SnapshotSsrOptionsinterfacesrc/vite/index.tsOptions for the snapshotSsr() Vite plugin.
snapshotSyncfunctionsrc/vite/index.tsVite 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.
SnapshotSyncOptionsinterfacesrc/vite/index.tsOptions for snapshotSync(), Snapshot’s Vite-driven Slingshot sync plugin.
staticParamsPluginfunctionsrc/vite/index.tsVite 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.

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:

  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:

{
"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:

NameDescription
optsOptional configuration. All fields have defaults.

Returns: A Vite Plugin object.

Example:

vite.config.ts
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:

NameDescription
optsSync 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:

NameDescription
optsPlugin configuration.

Returns: A Vite Plugin object.

Example:

Standalone usage (if needed outside snapshotSsr)
```ts
import { staticParamsPlugin } from '@lastshotlabs/snapshot/vite'
// vite.config.ts
export default defineConfig({
plugins: [staticParamsPlugin({ clientOutDir: 'dist/client' })],
})
---