Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tanstack/router/llms.txt
Use this file to discover all available pages before exploring further.
Webpack Plugin
The TanStack Router Webpack plugin provides integration with Webpack, enabling route generation and code splitting for your router application.Installation
Basic Usage
Add the plugin to yourwebpack.config.js:
Configuration
The plugin accepts the same configuration options as the Vite plugin:Configuration Options
Route Generation
routesDirectory
- Type:
string - Default:
'./src/routes' - The directory where your route files are located.
generatedRouteTree
- Type:
string - Default:
'./src/routeTree.gen.ts' - The file where the generated route tree will be written.
routeFilePrefix
- Type:
string - Optional
- A prefix to require for all route files.
routeFileIgnorePrefix
- Type:
string - Default:
'-' - Files starting with this prefix will be ignored during route generation.
Code Splitting
codeSplittingOptions
- Type:
CodeSplittingOptions - Optional
- Controls how routes are code-split.
TypeScript Options
disableTypes
- Type:
boolean - Default:
false - Disable TypeScript type generation.
quoteStyle
- Type:
'single' | 'double' - Default:
'single' - Quote style for generated code.
semicolons
- Type:
boolean - Default:
false - Whether to include semicolons in generated code.
Separate Plugins
For more granular control, use individual plugins:Route Generator Only
Code Splitter Only
How It Works
The Webpack plugin is built using unplugin, which provides a unified plugin interface across multiple build tools. The plugin:- Watches your routes directory for changes
- Generates a typed route tree file
- Transforms route imports for code splitting
- Enables hot module replacement for route updates
Examples
Basic React Setup
With Code Splitting
Development vs Production
TypeScript Configuration
Ensure yourtsconfig.json includes the generated route tree:
Troubleshooting
Plugin Not Running
Make sure the plugin is added to theplugins array in your Webpack config.
Route Tree Not Updating
In development mode, Webpack should watch for file changes automatically. If routes aren’t updating:- Check that your
routesDirectoryis correct - Verify that Webpack’s watch mode is enabled
- Try restarting the development server
Build Errors
If you encounter build errors:- Ensure all dependencies are installed
- Check that your route files have valid exports
- Verify TypeScript configuration is correct
Migration from Other Plugins
If you’re migrating from the standalone@tanstack/router-vite-plugin, the Webpack plugin provides equivalent functionality with the same configuration API.