Skip to content

Commit 17ec180

Browse files
docs(solid-router): rspack/build guides and example (#5834)
* docs(solid-router): add rspack docs * add rspack docs * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 71f9c7d commit 17ec180

File tree

27 files changed

+924
-268
lines changed

27 files changed

+924
-268
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
title: Installation with Rspack
3+
---
4+
5+
[//]: # 'BundlerConfiguration'
6+
7+
To use file-based routing with **Rspack** or **Rsbuild**, you'll need to install the `@tanstack/router-plugin` package.
8+
9+
```sh
10+
npm install -D @tanstack/router-plugin
11+
```
12+
13+
Once installed, you'll need to add the plugin to your configuration.
14+
15+
```tsx
16+
// rsbuild.config.ts
17+
import { defineConfig } from '@rsbuild/core'
18+
import { pluginBabel } from '@rsbuild/plugin-babel'
19+
import { pluginSolid } from '@rsbuild/plugin-solid'
20+
import { tanstackRouter } from '@tanstack/router-plugin/rspack'
21+
22+
export default defineConfig({
23+
plugins: [
24+
pluginBabel({
25+
include: /\.(?:jsx|tsx)$/,
26+
}),
27+
pluginSolid(),
28+
],
29+
tools: {
30+
rspack: {
31+
plugins: [tanstackRouter({ target: 'solid', autoCodeSplitting: true })],
32+
},
33+
},
34+
})
35+
```
36+
37+
Or, you can clone our [Quickstart Rspack/Rsbuild example](https://github.com/TanStack/router/tree/main/examples/solid/quickstart-rspack-file-based) and get started.
38+
39+
Now that you've added the plugin to your Rspack/Rsbuild configuration, you're all set to start using file-based routing with TanStack Router.
40+
41+
[//]: # 'BundlerConfiguration'
42+
43+
## Ignoring the generated route tree file
44+
45+
If your project is configured to use a linter and/or formatter, you may want to ignore the generated route tree file. This file is managed by TanStack Router and therefore shouldn't be changed by your linter or formatter.
46+
47+
Here are some resources to help you ignore the generated route tree file:
48+
49+
- Prettier - [https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore](https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore)
50+
- ESLint - [https://eslint.org/docs/latest/use/configure/ignore#ignoring-files](https://eslint.org/docs/latest/use/configure/ignore#ignoring-files)
51+
- Biome - [https://biomejs.dev/reference/configuration/#filesignore](https://biomejs.dev/reference/configuration/#filesignore)
52+
53+
> [!WARNING]
54+
> If you are using VSCode, you may experience the route tree file unexpectedly open (with errors) after renaming a route.
55+
56+
You can prevent that from the VSCode settings by marking the file as readonly. Our recommendation is to also exclude it from search results and file watcher with the following settings:
57+
58+
```json
59+
{
60+
"files.readonlyInclude": {
61+
"**/routeTree.gen.ts": true
62+
},
63+
"files.watcherExclude": {
64+
"**/routeTree.gen.ts": true
65+
},
66+
"search.exclude": {
67+
"**/routeTree.gen.ts": true
68+
}
69+
}
70+
```
71+
72+
You can use those settings either at a user level or only for a single workspace by creating the file `.vscode/settings.json` at the root of your project.
73+
74+
## Configuration
75+
76+
When using the TanStack Router Plugin with Rspack (or Rsbuild) for File-based routing, it comes with some sane defaults that should work for most projects:
77+
78+
```json
79+
{
80+
"routesDirectory": "./src/routes",
81+
"generatedRouteTree": "./src/routeTree.gen.ts",
82+
"routeFileIgnorePrefix": "-",
83+
"quoteStyle": "single"
84+
}
85+
```
86+
87+
If these defaults work for your project, you don't need to configure anything at all! However, if you need to customize the configuration, you can do so by editing the configuration object passed into the `tanstackRouter` function.
88+
89+
You can find all the available configuration options in the [File-based Routing API Reference](../../../../api/file-based-routing.md).

examples/solid/quickstart-esbuild-file-based/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ctx = await esbuild.context({
1313
format: 'esm',
1414
target: ['esnext'],
1515
sourcemap: true,
16+
conditions: ['style'],
1617
plugins: [
1718
solidPlugin(),
1819
tanstackRouter({ target: 'solid', autoCodeSplitting: true }),

examples/solid/quickstart-esbuild-file-based/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
"start": "dev"
1010
},
1111
"dependencies": {
12+
"@tanstack/router-plugin": "^1.135.2",
1213
"@tanstack/solid-router": "^1.135.2",
1314
"@tanstack/solid-router-devtools": "^1.135.2",
14-
"@tanstack/router-plugin": "^1.135.2",
15-
"solid-js": "^1.9.10",
1615
"redaxios": "^0.5.1",
16+
"solid-js": "^1.9.10",
17+
"tailwindcss": "^4.1.17",
1718
"zod": "^3.24.2"
1819
},
1920
"devDependencies": {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
plugins: {
3+
'@tailwindcss/postcss': {},
4+
},
5+
}

examples/solid/quickstart-esbuild-file-based/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { render } from 'solid-js/web'
22
import { RouterProvider, createRouter } from '@tanstack/solid-router'
33
import { routeTree } from './routeTree.gen'
4+
import './styles.css'
45

56
// Set up a Router instance
67
const router = createRouter({
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import 'tailwindcss';
2+
3+
@layer base {
4+
*,
5+
::after,
6+
::before,
7+
::backdrop,
8+
::file-selector-button {
9+
border-color: var(--color-gray-200, currentcolor);
10+
}
11+
}
12+
13+
html {
14+
color-scheme: light dark;
15+
}
16+
* {
17+
@apply border-gray-200 dark:border-gray-800;
18+
}
19+
body {
20+
@apply bg-gray-50 text-gray-950 dark:bg-gray-900 dark:text-gray-200;
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Local
2+
.DS_Store
3+
*.local
4+
*.log*
5+
6+
# Dist
7+
node_modules
8+
dist/
9+
10+
# IDE
11+
.idea
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"files.watcherExclude": {
3+
"**/routeTree.gen.ts": true
4+
},
5+
"search.exclude": {
6+
"**/routeTree.gen.ts": true
7+
},
8+
"files.readonlyInclude": {
9+
"**/routeTree.gen.ts": true
10+
}
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example
2+
3+
To run this example:
4+
5+
- `npm install` or `yarn`
6+
- `npm start` or `yarn start`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "tanstack-router-solid-example-quickstart-rspack-file-based",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "rsbuild dev --port 3000",
7+
"build": "rsbuild build && tsc --noEmit",
8+
"preview": "rsbuild preview"
9+
},
10+
"dependencies": {
11+
"@tailwindcss/postcss": "^4.1.15",
12+
"@tanstack/solid-router": "^1.135.2",
13+
"@tanstack/solid-router-devtools": "^1.135.2",
14+
"postcss": "^8.5.1",
15+
"solid-js": "^1.9.10",
16+
"tailwindcss": "^4.1.15"
17+
},
18+
"devDependencies": {
19+
"@rsbuild/core": "1.2.4",
20+
"@rsbuild/plugin-babel": "^1.0.6",
21+
"@rsbuild/plugin-solid": "1.0.6",
22+
"@tanstack/router-plugin": "^1.135.2",
23+
"typescript": "^5.6.2"
24+
}
25+
}

0 commit comments

Comments
 (0)