Skip to content

Commit da9adf0

Browse files
justin808claude
andcommitted
Add TanStack Router Webpack plugin support
The TanStack Router plugin was only configured for Rspack bundler. If someone switched to Webpack using bin/switch-bundler, the route tree wouldn't be auto-generated, breaking the file-based routing. - Extract router plugin config to shared object - Add else branch for Webpack bundler using TanStackRouterWebpack - Both bundlers now have proper route tree generation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5e7875b commit da9adf0

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

demos/basic-v16-rspack-tanstack/config/webpack/clientWebpackConfig.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,30 @@ const configureClient = () => {
1414
// client config is going to try to load chunks.
1515
delete clientConfig.entry['server-bundle'];
1616

17-
// Add TanStack Router plugin for file-based routing (Rspack only)
17+
// Add TanStack Router plugin for file-based routing
18+
const routerPluginConfig = {
19+
target: 'react',
20+
autoCodeSplitting: true,
21+
routesDirectory: path.resolve(__dirname, '../../app/javascript/src/routes'),
22+
generatedRouteTree: path.resolve(__dirname, '../../app/javascript/src/routeTree.gen.ts'),
23+
};
24+
25+
clientConfig.plugins = clientConfig.plugins || [];
26+
1827
if (config.assets_bundler === 'rspack') {
1928
try {
2029
const { TanStackRouterRspack } = require('@tanstack/router-plugin/rspack');
21-
clientConfig.plugins = clientConfig.plugins || [];
22-
clientConfig.plugins.push(
23-
TanStackRouterRspack({
24-
target: 'react',
25-
autoCodeSplitting: true,
26-
routesDirectory: path.resolve(__dirname, '../../app/javascript/src/routes'),
27-
generatedRouteTree: path.resolve(__dirname, '../../app/javascript/src/routeTree.gen.ts'),
28-
})
29-
);
30+
clientConfig.plugins.push(TanStackRouterRspack(routerPluginConfig));
31+
} catch (e) {
32+
console.warn('TanStack Router Rspack plugin not available:', e.message);
33+
}
34+
} else {
35+
// Webpack bundler
36+
try {
37+
const { TanStackRouterWebpack } = require('@tanstack/router-plugin/webpack');
38+
clientConfig.plugins.push(TanStackRouterWebpack(routerPluginConfig));
3039
} catch (e) {
31-
console.warn('TanStack Router plugin not available:', e.message);
40+
console.warn('TanStack Router Webpack plugin not available:', e.message);
3241
}
3342
}
3443

0 commit comments

Comments
 (0)