Rspack Plugin
The TanStack Router Rspack plugin provides integration with Rspack, a fast Rust-based bundler. It enables route generation and code splitting for your router application.Installation
Basic Usage
Add the plugin to your Rspack configuration:Configuration
The plugin accepts the same configuration options as other TanStack Router plugins: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.
routeFileIgnorePattern
- Type:
string - Optional
- A regex pattern to ignore specific route files.
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 Rspack plugin is built using unplugin, which provides a unified plugin interface across 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
Custom Routes Directory
Multiple Frameworks
Rspack supports multiple frameworks. Here’s an example with Solid:TypeScript Configuration
Ensure yourtsconfig.json includes the generated route tree:
Performance
Rspack is a high-performance bundler written in Rust. The TanStack Router plugin integrates seamlessly to provide:- Fast route generation
- Efficient code splitting
- Quick HMR updates
- Optimized production builds
Troubleshooting
Plugin Not Running
Make sure the plugin is added to thetools.rspack.plugins array in your Rsbuild config.
Route Tree Not Updating
In development mode, Rspack watches for file changes automatically. If routes aren’t updating:- Check that your
routesDirectoryis correct - Verify that Rspack’s watch mode is enabled
- Try restarting the development server
Build Errors
If you encounter build errors:- Ensure
@rsbuild/coreand@tanstack/router-pluginare installed - Check that your route files have valid exports
- Verify TypeScript configuration is correct
- Check Rspack version compatibility
HMR Not Working
If Hot Module Replacement isn’t working:- Ensure
codeSplittingOptions.addHmris enabled - Check that you’re in development mode
- Verify Rsbuild’s dev server is running
Migration from Webpack
If you’re migrating from Webpack to Rspack:- Replace
@tanstack/router-plugin/webpackwith@tanstack/router-plugin/rspack - Update your config to use Rsbuild’s format
- The plugin configuration remains the same