Skip to main content
The TanStack Start Vite plugin is the core integration that enables full-stack functionality in your application. It handles server functions, routing, SSR, and build configuration.

Installation

The plugin is included with your framework-specific Start package:

Basic Setup

Add the plugin to your vite.config.ts:

Configuration Options

The plugin accepts a configuration object with the following options:

srcDirectory

Specify the source directory for your application.

start

Configure the Start entry point.

router

Configure router-specific options.

Router Options

  • entry: Custom router entry file path
  • basepath: Base path for all routes (default: inherits from Vite’s base option)
  • routesDirectory: Directory containing route files (default: 'routes')
  • generatedRouteTree: Path for generated route tree file (default: 'routeTree.gen.ts')

client

Configure client-side build options.

server

Configure server-side build options. See Server Options for details.

serverFns

Configure server function behavior.

serverFns Options

  • base: Base path for server function endpoints (default: '/_serverFn')
  • generateFunctionId: Custom function to generate unique IDs for server functions

pages

Define pages for prerendering and sitemap generation.

prerender

Configure static site generation. See Static Generation for details.

sitemap

Configure sitemap generation.

spa

Configure Single Page Application (SPA) mode.

dev

Configure development server options.

importProtection

Configure import protection to prevent server code from being bundled in the client.

Import Protection Options

  • enabled: Enable import protection (default: true)
  • behavior: How to handle violations - 'error' throws, 'mock' creates mock exports
  • mockAccess: Control runtime diagnostics when mocked imports are accessed
  • client: Rules for client-side imports
    • specifiers: Array of import specifiers to deny (strings or RegExp)
    • files: Array of file patterns to deny (strings or RegExp)
    • excludeFiles: Array of file patterns to exclude from checking
  • server: Rules for server-side imports
  • onViolation: Callback when a violation occurs
  • maxTraceDepth: Maximum depth to trace import chains
  • log: Control logging frequency for violations

vite

Advanced Vite integration options.

Complete Example

Here’s a comprehensive configuration example:

Environment Variables

The plugin automatically defines several environment variables that are replaced at build time:
  • TSS_SERVER_FN_BASE: Base path for server functions
  • TSS_CLIENT_OUTPUT_DIR: Client output directory
  • TSS_ROUTER_BASEPATH: Router base path
  • TSS_SHELL: Whether SPA shell is enabled (dev only)
  • TSS_DEV_SERVER: Whether running in dev server
  • TSS_DEV_SSR_STYLES_ENABLED: Whether SSR styles are enabled in dev
  • TSS_DEV_SSR_STYLES_BASEPATH: Base path for SSR styles in dev
These are available via process.env.TSS_* or import.meta.env.TSS_*.

Next Steps

Build Options

Learn about build configuration options

Server Options

Configure server-side rendering and deployment