@tanstack/router-plugin 1.166.12 → 1.166.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/intent.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ // Auto-generated by @tanstack/intent setup
3
+ // Exposes the intent end-user CLI for consumers of this library.
4
+ // Commit this file, then add to your package.json:
5
+ // "bin": { "intent": "./bin/intent.js" }
6
+ try {
7
+ await import('@tanstack/intent/intent-library')
8
+ } catch (e) {
9
+ const isModuleNotFound =
10
+ e?.code === 'ERR_MODULE_NOT_FOUND' || e?.code === 'MODULE_NOT_FOUND'
11
+ const missingIntentLibrary =
12
+ typeof e?.message === 'string' && e.message.includes('@tanstack/intent')
13
+
14
+ if (isModuleNotFound && missingIntentLibrary) {
15
+ console.error('@tanstack/intent is not installed.')
16
+ console.error('')
17
+ console.error('Install it as a dev dependency:')
18
+ console.error(' npm add -D @tanstack/intent')
19
+ console.error('')
20
+ console.error('Or run directly:')
21
+ console.error(' npx @tanstack/intent@latest list')
22
+ process.exit(1)
23
+ }
24
+ throw e
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-plugin",
3
- "version": "1.166.12",
3
+ "version": "1.166.14",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -81,7 +81,10 @@
81
81
  "sideEffects": false,
82
82
  "files": [
83
83
  "dist",
84
- "src"
84
+ "src",
85
+ "skills",
86
+ "bin",
87
+ "!skills/_artifacts"
85
88
  ],
86
89
  "engines": {
87
90
  "node": ">=20.19"
@@ -96,12 +99,13 @@
96
99
  "chokidar": "^3.6.0",
97
100
  "unplugin": "^2.1.2",
98
101
  "zod": "^3.24.2",
99
- "@tanstack/router-core": "1.167.3",
100
- "@tanstack/router-generator": "1.166.11",
102
+ "@tanstack/router-core": "1.167.5",
103
+ "@tanstack/router-generator": "1.166.13",
101
104
  "@tanstack/router-utils": "1.161.6",
102
- "@tanstack/virtual-file-routes": "1.161.6"
105
+ "@tanstack/virtual-file-routes": "1.161.7"
103
106
  },
104
107
  "devDependencies": {
108
+ "@tanstack/intent": "^0.0.14",
105
109
  "@types/babel__core": "^7.20.5",
106
110
  "@types/babel__template": "^7.4.4",
107
111
  "@types/babel__traverse": "^7.28.0"
@@ -111,7 +115,7 @@
111
115
  "vite": ">=5.0.0 || >=6.0.0 || >=7.0.0",
112
116
  "vite-plugin-solid": "^2.11.10",
113
117
  "webpack": ">=5.92.0",
114
- "@tanstack/react-router": "^1.167.3"
118
+ "@tanstack/react-router": "^1.167.5"
115
119
  },
116
120
  "peerDependenciesMeta": {
117
121
  "@rsbuild/core": {
@@ -130,6 +134,9 @@
130
134
  "optional": true
131
135
  }
132
136
  },
137
+ "bin": {
138
+ "intent": "./bin/intent.js"
139
+ },
133
140
  "scripts": {
134
141
  "clean": "rimraf ./dist && rimraf ./coverage",
135
142
  "clean:snapshots": "rimraf **/*snapshot* --glob",
@@ -0,0 +1,236 @@
1
+ ---
2
+ name: router-plugin
3
+ description: >-
4
+ TanStack Router bundler plugin for route generation and automatic
5
+ code splitting. Supports Vite, Webpack, Rspack, and esbuild.
6
+ Configures autoCodeSplitting, routesDirectory, target framework,
7
+ and code split groupings.
8
+ type: core
9
+ library: tanstack-router
10
+ library_version: '1.166.2'
11
+ sources:
12
+ - TanStack/router:packages/router-plugin/src
13
+ - TanStack/router:docs/router/routing/file-based-routing.md
14
+ - TanStack/router:docs/router/guide/code-splitting.md
15
+ ---
16
+
17
+ # Router Plugin (`@tanstack/router-plugin`)
18
+
19
+ Bundler plugin that powers TanStack Router's file-based routing and automatic code splitting. Works with Vite, Webpack, Rspack, and esbuild via unplugin.
20
+
21
+ > **CRITICAL**: The router plugin MUST come before the framework plugin (React, Solid, Vue) in the Vite config. Wrong order causes route generation and code splitting to fail silently.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install -D @tanstack/router-plugin
27
+ ```
28
+
29
+ ## Bundler Setup
30
+
31
+ ### Vite (most common)
32
+
33
+ ```ts
34
+ // vite.config.ts
35
+ import { defineConfig } from 'vite'
36
+ import react from '@vitejs/plugin-react'
37
+ import { tanstackRouter } from '@tanstack/router-plugin/vite'
38
+
39
+ export default defineConfig({
40
+ plugins: [
41
+ // MUST come before react()
42
+ tanstackRouter({
43
+ target: 'react',
44
+ autoCodeSplitting: true,
45
+ }),
46
+ react(),
47
+ ],
48
+ })
49
+ ```
50
+
51
+ ### Webpack
52
+
53
+ ```ts
54
+ // webpack.config.js
55
+ const { tanstackRouter } = require('@tanstack/router-plugin/webpack')
56
+
57
+ module.exports = {
58
+ plugins: [
59
+ tanstackRouter({
60
+ target: 'react',
61
+ autoCodeSplitting: true,
62
+ }),
63
+ ],
64
+ }
65
+ ```
66
+
67
+ ### Rspack
68
+
69
+ ```ts
70
+ // rspack.config.js
71
+ const { tanstackRouter } = require('@tanstack/router-plugin/rspack')
72
+
73
+ module.exports = {
74
+ plugins: [
75
+ tanstackRouter({
76
+ target: 'react',
77
+ autoCodeSplitting: true,
78
+ }),
79
+ ],
80
+ }
81
+ ```
82
+
83
+ ### esbuild
84
+
85
+ ```ts
86
+ import { tanstackRouter } from '@tanstack/router-plugin/esbuild'
87
+ import esbuild from 'esbuild'
88
+
89
+ esbuild.build({
90
+ plugins: [
91
+ tanstackRouter({
92
+ target: 'react',
93
+ autoCodeSplitting: true,
94
+ }),
95
+ ],
96
+ })
97
+ ```
98
+
99
+ ## Configuration Options
100
+
101
+ ### Core Options
102
+
103
+ | Option | Type | Default | Description |
104
+ | ----------------------- | ----------------------------- | -------------------------- | ------------------------------------------ |
105
+ | `target` | `'react' \| 'solid' \| 'vue'` | `'react'` | Target framework |
106
+ | `routesDirectory` | `string` | `'./src/routes'` | Directory containing route files |
107
+ | `generatedRouteTree` | `string` | `'./src/routeTree.gen.ts'` | Path for generated route tree |
108
+ | `autoCodeSplitting` | `boolean` | `undefined` | Enable automatic code splitting |
109
+ | `enableRouteGeneration` | `boolean` | `true` | Set to `false` to disable route generation |
110
+
111
+ ### File Convention Options
112
+
113
+ | Option | Type | Default | Description |
114
+ | ------------------------ | ------------------------------------------------------- | ----------- | ------------------------------------ |
115
+ | `routeFilePrefix` | `string` | `undefined` | Prefix filter for route files |
116
+ | `routeFileIgnorePrefix` | `string` | `'-'` | Prefix to exclude files from routing |
117
+ | `routeFileIgnorePattern` | `string` | `undefined` | Pattern to exclude from routing |
118
+ | `indexToken` | `string \| RegExp \| { regex: string; flags?: string }` | `'index'` | Token identifying index routes |
119
+ | `routeToken` | `string \| RegExp \| { regex: string; flags?: string }` | `'route'` | Token identifying route config files |
120
+
121
+ ### Code Splitting Options
122
+
123
+ ```ts
124
+ tanstackRouter({
125
+ target: 'react',
126
+ autoCodeSplitting: true,
127
+ codeSplittingOptions: {
128
+ // Default groupings for all routes
129
+ defaultBehavior: [['component'], ['errorComponent'], ['notFoundComponent']],
130
+
131
+ // Per-route custom splitting
132
+ splitBehavior: ({ routeId }) => {
133
+ if (routeId === '/dashboard') {
134
+ // Keep loader and component together for dashboard
135
+ return [['loader', 'component'], ['errorComponent']]
136
+ }
137
+ // Return undefined to use defaultBehavior
138
+ },
139
+ },
140
+ })
141
+ ```
142
+
143
+ ### Output Options
144
+
145
+ | Option | Type | Default | Description |
146
+ | --------------------------- | ---------------------- | ----------- | -------------------------------------------- |
147
+ | `quoteStyle` | `'single' \| 'double'` | `'single'` | Quote style in generated code |
148
+ | `semicolons` | `boolean` | `false` | Use semicolons in generated code |
149
+ | `disableTypes` | `boolean` | `false` | Disable TypeScript types |
150
+ | `disableLogging` | `boolean` | `false` | Suppress plugin logs |
151
+ | `addExtensions` | `boolean \| string` | `false` | Add file extensions to imports |
152
+ | `enableRouteTreeFormatting` | `boolean` | `true` | Format generated route tree |
153
+ | `verboseFileRoutes` | `boolean` | `undefined` | When `false`, auto-imports `createFileRoute` |
154
+
155
+ ### Virtual Route Config
156
+
157
+ ```ts
158
+ import { routes } from './routes'
159
+
160
+ tanstackRouter({
161
+ target: 'react',
162
+ virtualRouteConfig: routes, // or './routes.ts'
163
+ })
164
+ ```
165
+
166
+ ## How It Works
167
+
168
+ The composed plugin assembles up to 4 sub-plugins:
169
+
170
+ 1. **Route Generator** (always) — Watches route files and generates `routeTree.gen.ts`
171
+ 2. **Code Splitter** (when `autoCodeSplitting: true`) — Splits route files into lazy-loaded chunks using virtual modules
172
+ 3. **Auto-Import** (when `verboseFileRoutes: false`) — Auto-injects `createFileRoute` imports
173
+ 4. **HMR** (dev mode, when code splitter is off) — Hot-reloads route changes without full refresh
174
+
175
+ ## Individual Plugin Exports
176
+
177
+ For advanced use, each sub-plugin is exported separately from the Vite entry:
178
+
179
+ ```ts
180
+ import {
181
+ tanstackRouter, // Composed (default)
182
+ tanstackRouterGenerator, // Generator only
183
+ tanStackRouterCodeSplitter, // Code splitter only
184
+ tanstackRouterAutoImport, // Auto-import only
185
+ } from '@tanstack/router-plugin/vite'
186
+ ```
187
+
188
+ ## Common Mistakes
189
+
190
+ ### 1. CRITICAL: Wrong plugin order in Vite config
191
+
192
+ The router plugin must come before the framework plugin. Otherwise, route generation and code splitting fail silently.
193
+
194
+ ```ts
195
+ // WRONG — react() before tanstackRouter()
196
+ plugins: [react(), tanstackRouter({ target: 'react' })]
197
+
198
+ // CORRECT — tanstackRouter() first
199
+ plugins: [tanstackRouter({ target: 'react' }), react()]
200
+ ```
201
+
202
+ ### 2. HIGH: Missing target option for non-React frameworks
203
+
204
+ The `target` defaults to `'react'`. For Solid or Vue, you must set it explicitly.
205
+
206
+ ```ts
207
+ // WRONG for Solid — generates React imports
208
+ tanstackRouter({ autoCodeSplitting: true })
209
+
210
+ // CORRECT for Solid
211
+ tanstackRouter({ target: 'solid', autoCodeSplitting: true })
212
+ ```
213
+
214
+ ### 3. MEDIUM: Confusing autoCodeSplitting with manual lazy routes
215
+
216
+ When `autoCodeSplitting` is enabled, the plugin handles splitting automatically. You do NOT need manual `createLazyRoute` or `lazyRouteComponent` calls — the plugin transforms your route files at build time.
217
+
218
+ ```tsx
219
+ // WRONG — manual lazy loading with autoCodeSplitting enabled
220
+ const LazyAbout = lazyRouteComponent(() => import('./about'))
221
+
222
+ // CORRECT — just write normal route files, plugin handles splitting
223
+ // src/routes/about.tsx
224
+ export const Route = createFileRoute('/about')({
225
+ component: AboutPage,
226
+ })
227
+
228
+ function AboutPage() {
229
+ return <h1>About</h1>
230
+ }
231
+ ```
232
+
233
+ ## Cross-References
234
+
235
+ - [router-core/code-splitting](../../../router-core/skills/router-core/code-splitting/SKILL.md) — manual code splitting concepts
236
+ - [virtual-file-routes](../../../virtual-file-routes/skills/virtual-file-routes/SKILL.md) — programmatic route trees