@tanstack/start-plugin-core 1.121.0-alpha.27 → 1.121.0-alpha.28

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.
Files changed (157) hide show
  1. package/dist/esm/{nitro-plugin/build-sitemap.d.ts → build-sitemap.d.ts} +3 -3
  2. package/dist/esm/{nitro-plugin/build-sitemap.js → build-sitemap.js} +19 -24
  3. package/dist/esm/build-sitemap.js.map +1 -0
  4. package/dist/esm/compilers.d.ts +1 -1
  5. package/dist/esm/compilers.js +6 -9
  6. package/dist/esm/compilers.js.map +1 -1
  7. package/dist/esm/constants.d.ts +6 -2
  8. package/dist/esm/constants.js +7 -10
  9. package/dist/esm/constants.js.map +1 -1
  10. package/dist/esm/debug.js.map +1 -1
  11. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  12. package/dist/esm/dev-server-plugin/plugin.d.ts +5 -5
  13. package/dist/esm/dev-server-plugin/plugin.js +118 -95
  14. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  15. package/dist/esm/index.d.ts +1 -1
  16. package/dist/esm/index.js +0 -4
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
  19. package/dist/esm/load-env-plugin/plugin.js +5 -8
  20. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  21. package/dist/esm/output-directory.d.ts +3 -0
  22. package/dist/esm/output-directory.js +14 -0
  23. package/dist/esm/output-directory.js.map +1 -0
  24. package/dist/esm/plugin.d.ts +11 -286
  25. package/dist/esm/plugin.js +171 -94
  26. package/dist/esm/plugin.js.map +1 -1
  27. package/dist/esm/post-server-build.d.ts +7 -0
  28. package/dist/esm/post-server-build.js +55 -0
  29. package/dist/esm/post-server-build.js.map +1 -0
  30. package/dist/esm/prerender.d.ts +11 -0
  31. package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +88 -71
  32. package/dist/esm/prerender.js.map +1 -0
  33. package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
  34. package/dist/esm/queue.js.map +1 -0
  35. package/dist/esm/resolve-entries.d.ts +8 -0
  36. package/dist/esm/resolve-entries.js +37 -0
  37. package/dist/esm/resolve-entries.js.map +1 -0
  38. package/dist/esm/schema.d.ts +1334 -6585
  39. package/dist/esm/schema.js +54 -86
  40. package/dist/esm/schema.js.map +1 -1
  41. package/dist/esm/start-compiler-plugin.js +7 -3
  42. package/dist/esm/start-compiler-plugin.js.map +1 -1
  43. package/dist/esm/start-manifest-plugin/plugin.d.ts +6 -3
  44. package/dist/esm/start-manifest-plugin/plugin.js +95 -100
  45. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  46. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +4 -5
  47. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  48. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
  49. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
  50. package/dist/esm/start-router-plugin/plugin.d.ts +1 -1
  51. package/dist/esm/start-router-plugin/plugin.js +26 -2
  52. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  53. package/dist/esm/start-router-plugin/route-tree-client-plugin.js +2 -1
  54. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
  55. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -1
  56. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +3 -4
  57. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
  58. package/dist/esm/utils.js.map +1 -1
  59. package/package.json +14 -18
  60. package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
  61. package/src/compilers.ts +1 -1
  62. package/src/constants.ts +12 -9
  63. package/src/dev-server-plugin/plugin.ts +146 -124
  64. package/src/index.ts +1 -5
  65. package/src/load-env-plugin/plugin.ts +6 -11
  66. package/src/output-directory.ts +18 -0
  67. package/src/plugin.ts +227 -119
  68. package/src/post-server-build.ts +73 -0
  69. package/src/{nitro-plugin/prerender.ts → prerender.ts} +95 -82
  70. package/src/resolve-entries.ts +52 -0
  71. package/src/schema.ts +89 -121
  72. package/src/start-compiler-plugin.ts +4 -0
  73. package/src/start-manifest-plugin/plugin.ts +121 -139
  74. package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +2 -2
  75. package/src/start-router-plugin/plugin.ts +26 -2
  76. package/src/start-router-plugin/route-tree-client-plugin.ts +2 -1
  77. package/src/start-router-plugin/virtual-route-tree-plugin.ts +3 -4
  78. package/dist/cjs/compilers.cjs +0 -416
  79. package/dist/cjs/compilers.cjs.map +0 -1
  80. package/dist/cjs/compilers.d.cts +0 -21
  81. package/dist/cjs/constants.cjs +0 -20
  82. package/dist/cjs/constants.cjs.map +0 -1
  83. package/dist/cjs/constants.d.cts +0 -6
  84. package/dist/cjs/debug.cjs +0 -5
  85. package/dist/cjs/debug.cjs.map +0 -1
  86. package/dist/cjs/debug.d.cts +0 -1
  87. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
  88. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
  89. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
  90. package/dist/cjs/dev-server-plugin/plugin.cjs +0 -136
  91. package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
  92. package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
  93. package/dist/cjs/index.cjs +0 -11
  94. package/dist/cjs/index.cjs.map +0 -1
  95. package/dist/cjs/index.d.cts +0 -3
  96. package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
  97. package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
  98. package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
  99. package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
  100. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
  101. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
  102. package/dist/cjs/nitro-plugin/plugin.cjs +0 -181
  103. package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
  104. package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
  105. package/dist/cjs/nitro-plugin/prerender.cjs +0 -173
  106. package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
  107. package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
  108. package/dist/cjs/nitro-plugin/queue.cjs +0 -131
  109. package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
  110. package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
  111. package/dist/cjs/plugin.cjs +0 -197
  112. package/dist/cjs/plugin.cjs.map +0 -1
  113. package/dist/cjs/plugin.d.cts +0 -291
  114. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -66
  115. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
  116. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
  117. package/dist/cjs/schema.cjs +0 -157
  118. package/dist/cjs/schema.cjs.map +0 -1
  119. package/dist/cjs/schema.d.cts +0 -8779
  120. package/dist/cjs/start-compiler-plugin.cjs +0 -74
  121. package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
  122. package/dist/cjs/start-compiler-plugin.d.cts +0 -13
  123. package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
  124. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
  125. package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -3
  126. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
  127. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
  128. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
  129. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
  130. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
  131. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
  132. package/dist/cjs/start-router-plugin/plugin.cjs +0 -21
  133. package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
  134. package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
  135. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -72
  136. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
  137. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
  138. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -30
  139. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
  140. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -4
  141. package/dist/cjs/utils.cjs +0 -18
  142. package/dist/cjs/utils.cjs.map +0 -1
  143. package/dist/cjs/utils.d.cts +0 -8
  144. package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
  145. package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
  146. package/dist/esm/nitro-plugin/plugin.js +0 -181
  147. package/dist/esm/nitro-plugin/plugin.js.map +0 -1
  148. package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
  149. package/dist/esm/nitro-plugin/prerender.js.map +0 -1
  150. package/dist/esm/nitro-plugin/queue.js.map +0 -1
  151. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
  152. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -49
  153. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
  154. package/src/nitro-plugin/plugin.ts +0 -244
  155. package/src/resolve-virtual-entries-plugin/plugin.ts +0 -63
  156. /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
  157. /package/src/{nitro-plugin/queue.ts → queue.ts} +0 -0
@@ -1,28 +1,21 @@
1
- import { readFileSync } from 'node:fs'
2
- import path from 'node:path'
3
1
  import { joinURL } from 'ufo'
4
2
  import { rootRouteId } from '@tanstack/router-core'
5
3
  import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
4
+ import { tsrSplit } from '@tanstack/router-plugin'
6
5
  import { resolveViteId } from '../utils'
7
- import { CLIENT_DIST_DIR } from '../constants'
8
- import type {
9
- PluginOption,
10
- ResolvedConfig,
11
- Manifest as ViteManifest,
12
- ManifestChunk as ViteManifestChunk,
13
- } from 'vite'
6
+ import { ENTRY_POINTS } from '../constants'
7
+ import type { PluginOption, Rollup } from 'vite'
14
8
  import type { RouterManagedTag } from '@tanstack/router-core'
15
- import type { TanStackStartOutputConfig } from '../plugin'
16
9
 
17
- const getCSSRecursively = (
18
- file: ViteManifestChunk,
19
- filesByRouteFilePath: ViteManifest,
10
+ export const getCSSRecursively = (
11
+ chunk: Rollup.OutputChunk,
12
+ chunksByFileName: Map<string, Rollup.OutputChunk>,
20
13
  basePath: string,
21
14
  ) => {
22
15
  const result: Array<RouterManagedTag> = []
23
16
 
24
17
  // Get all css imports from the file
25
- for (const cssFile of file.css ?? []) {
18
+ for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
26
19
  result.push({
27
20
  tag: 'link',
28
21
  attrs: {
@@ -34,11 +27,11 @@ const getCSSRecursively = (
34
27
  }
35
28
 
36
29
  // Recursively get CSS from imports
37
- for (const imp of file.imports ?? []) {
38
- const importInfo = filesByRouteFilePath[imp]
39
- if (importInfo) {
30
+ for (const importedFileName of chunk.imports) {
31
+ const importedChunk = chunksByFileName.get(importedFileName)
32
+ if (importedChunk) {
40
33
  result.push(
41
- ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),
34
+ ...getCSSRecursively(importedChunk, chunksByFileName, basePath),
42
35
  )
43
36
  }
44
37
  }
@@ -47,21 +40,12 @@ const getCSSRecursively = (
47
40
  }
48
41
 
49
42
  const resolvedModuleId = resolveViteId(VIRTUAL_MODULES.startManifest)
50
- export function startManifestPlugin(
51
- opts: TanStackStartOutputConfig,
52
- ): PluginOption {
53
- let config: ResolvedConfig
54
-
43
+ export function startManifestPlugin(opts: {
44
+ getClientBundle: () => Rollup.OutputBundle
45
+ }): PluginOption {
55
46
  return {
56
47
  name: 'tanstack-start:start-manifest-plugin',
57
48
  enforce: 'pre',
58
-
59
- configResolved(resolvedConfig) {
60
- config = resolvedConfig
61
- },
62
- // configEnvironment(env, envConfig) {
63
- // config = envConfig.
64
- // },
65
49
  resolveId: {
66
50
  filter: { id: new RegExp(VIRTUAL_MODULES.startManifest) },
67
51
  handler(id) {
@@ -83,131 +67,129 @@ export function startManifestPlugin(
83
67
  return `export default {}`
84
68
  }
85
69
 
86
- // If we're in development, return a dummy manifest
87
- if (config.command === 'serve') {
88
- return `export const tsrStartManifest = () => ({
89
- routes: {}
90
- })`
91
- }
92
-
93
70
  // This is the basepath for the application
94
71
  const APP_BASE = globalThis.TSS_APP_BASE
95
72
 
96
- const clientViteManifestPath = path.resolve(
97
- opts.root,
98
- CLIENT_DIST_DIR,
99
- '.vite',
100
- 'manifest.json',
101
- )
102
-
103
- let viteManifest: ViteManifest
104
- try {
105
- viteManifest = JSON.parse(
106
- readFileSync(clientViteManifestPath, 'utf-8'),
107
- )
108
- } catch (err) {
109
- console.error(err)
110
- throw new Error(
111
- `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,
112
- )
73
+ // If we're in development, return a dummy manifest
74
+ if (this.environment.config.command === 'serve') {
75
+ return `export const tsrStartManifest = () => ({
76
+ routes: {},
77
+ clientEntry: '${joinURL(APP_BASE, '@id', ENTRY_POINTS.client)}',
78
+ })`
113
79
  }
114
80
 
115
81
  // This the manifest pulled from the generated route tree and later used by the Router.
116
- // i.e what's located in `src/generatedRouteTree.gen.ts`
82
+ // i.e what's located in `src/routeTree.gen.ts`
117
83
  const routeTreeRoutes = globalThis.TSS_ROUTES_MANIFEST.routes
118
84
 
119
85
  // This is where hydration will start, from when the SSR'd page reaches the browser.
120
- // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.
121
- let entryFile: ViteManifestChunk | undefined
122
-
123
- const filesByRouteFilePath: ViteManifest = Object.fromEntries(
124
- Object.entries(viteManifest).map(([k, v]) => {
125
- if (v.isEntry) {
126
- if (entryFile !== undefined) {
127
- console.error(
128
- `multiple entries detected`,
129
- entryFile.file,
130
- v.file,
86
+ let entryFile: Rollup.OutputChunk | undefined
87
+
88
+ const clientBundle = opts.getClientBundle()
89
+ const chunksByFileName = new Map<string, Rollup.OutputChunk>()
90
+
91
+ const routeChunks: Record<
92
+ string /** fullPath of route file **/,
93
+ Array<Rollup.OutputChunk>
94
+ > = {}
95
+ for (const bundleEntry of Object.values(clientBundle)) {
96
+ if (bundleEntry.type === 'chunk') {
97
+ chunksByFileName.set(bundleEntry.fileName, bundleEntry)
98
+ if (bundleEntry.isEntry) {
99
+ if (entryFile) {
100
+ throw new Error(
101
+ `multiple entries detected: ${entryFile.fileName} ${bundleEntry.fileName}`,
131
102
  )
132
103
  }
133
- entryFile = v
104
+ entryFile = bundleEntry
134
105
  }
135
-
136
- const rPath = k.split('?')[0]
137
-
138
- return [rPath, v]
139
- }, {}),
140
- )
141
-
142
- const routesDirectoryFromRoot = path.relative(
143
- opts.root,
144
- opts.tsr.routesDirectory,
145
- )
106
+ const routePieces = bundleEntry.moduleIds.flatMap((m) => {
107
+ const [id, query] = m.split('?')
108
+ if (id === undefined) {
109
+ throw new Error('expected id to be defined')
110
+ }
111
+ if (query === undefined) {
112
+ return []
113
+ }
114
+ const searchParams = new URLSearchParams(query)
115
+ const split = searchParams.get(tsrSplit)
116
+
117
+ if (split !== null) {
118
+ return {
119
+ id,
120
+ split,
121
+ }
122
+ }
123
+ return []
124
+ })
125
+ if (routePieces.length > 0) {
126
+ routePieces.forEach((r) => {
127
+ let array = routeChunks[r.id]
128
+ if (array === undefined) {
129
+ array = []
130
+ routeChunks[r.id] = array
131
+ }
132
+ array.push(bundleEntry)
133
+ })
134
+ }
135
+ }
136
+ }
146
137
 
147
138
  // Add preloads to the routes from the vite manifest
148
139
  Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {
149
- const file =
150
- filesByRouteFilePath[
151
- path.posix.join(routesDirectoryFromRoot, v.filePath as string)
152
- ]
153
-
154
- if (file) {
155
- // Map the relevant imports to their route paths,
156
- // so that it can be imported in the browser.
157
- const preloads = (file.imports ?? []).map((d) => {
158
- const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)
159
- return assetPath
140
+ if (!v.filePath) {
141
+ throw new Error(`expected filePath to be set for ${routeId}`)
142
+ }
143
+ const chunks = routeChunks[v.filePath]
144
+ if (chunks) {
145
+ chunks.forEach((chunk) => {
146
+ // Map the relevant imports to their route paths,
147
+ // so that it can be imported in the browser.
148
+ const preloads = chunk.imports.map((d) => {
149
+ const assetPath = joinURL(APP_BASE, d)
150
+ return assetPath
151
+ })
152
+
153
+ // Since this is the most important JS entry for the route,
154
+ // it should be moved to the front of the preloads so that
155
+ // it has the best chance of being loaded first.
156
+ preloads.unshift(joinURL(APP_BASE, chunk.fileName))
157
+
158
+ const cssAssetsList = getCSSRecursively(
159
+ chunk,
160
+ chunksByFileName,
161
+ APP_BASE,
162
+ )
163
+
164
+ routeTreeRoutes[routeId] = {
165
+ ...v,
166
+ assets: [...(v.assets || []), ...cssAssetsList],
167
+ preloads: [...(v.preloads || []), ...preloads],
168
+ }
160
169
  })
161
-
162
- // Since this is the most important JS entry for the route,
163
- // it should be moved to the front of the preloads so that
164
- // it has the best chance of being loaded first.
165
- if (file.file) {
166
- preloads.unshift(path.join(APP_BASE, file.file))
167
- }
168
-
169
- const cssAssetsList = getCSSRecursively(
170
- file,
171
- filesByRouteFilePath,
172
- APP_BASE,
173
- )
174
-
175
- routeTreeRoutes[routeId] = {
176
- ...v,
177
- assets: [...(v.assets || []), ...cssAssetsList],
178
- preloads,
179
- }
180
170
  }
181
171
  })
182
172
 
183
- if (entryFile) {
184
- routeTreeRoutes[rootRouteId]!.preloads = [
185
- joinURL(APP_BASE, entryFile.file),
186
- ...(entryFile.imports?.map((d) =>
187
- joinURL(APP_BASE, viteManifest[d]!.file),
188
- ) || []),
189
- ]
190
-
191
- // Gather all the CSS files from the entry file in
192
- // the `css` key and add them to the root route
193
- const entryCssAssetsList = getCSSRecursively(
194
- entryFile,
195
- filesByRouteFilePath,
196
- APP_BASE,
197
- )
198
-
199
- routeTreeRoutes[rootRouteId]!.assets = [
200
- ...(routeTreeRoutes[rootRouteId]!.assets || []),
201
- ...entryCssAssetsList,
202
- {
203
- tag: 'script',
204
- attrs: {
205
- src: joinURL(APP_BASE, entryFile.file),
206
- type: 'module',
207
- },
208
- },
209
- ]
173
+ if (!entryFile) {
174
+ throw new Error('No entry file found')
210
175
  }
176
+ routeTreeRoutes[rootRouteId]!.preloads = [
177
+ joinURL(APP_BASE, entryFile.fileName),
178
+ ...entryFile.imports.map((d) => joinURL(APP_BASE, d)),
179
+ ]
180
+
181
+ // Gather all the CSS files from the entry file in
182
+ // the `css` key and add them to the root route
183
+ const entryCssAssetsList = getCSSRecursively(
184
+ entryFile,
185
+ chunksByFileName,
186
+ APP_BASE,
187
+ )
188
+
189
+ routeTreeRoutes[rootRouteId]!.assets = [
190
+ ...(routeTreeRoutes[rootRouteId]!.assets || []),
191
+ ...entryCssAssetsList,
192
+ ]
211
193
 
212
194
  const recurseRoute = (
213
195
  route: {
@@ -232,14 +214,14 @@ export function startManifestPlugin(
232
214
  }
233
215
  }
234
216
 
235
- // @ts-expect-error
236
- recurseRoute(routeTreeRoutes[rootRouteId])
217
+ recurseRoute(routeTreeRoutes[rootRouteId]!)
237
218
 
238
- const routesManifest = {
219
+ const startManifest = {
239
220
  routes: routeTreeRoutes,
221
+ clientEntry: joinURL(APP_BASE, entryFile.fileName),
240
222
  }
241
223
 
242
- return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`
224
+ return `export const tsrStartManifest = () => (${JSON.stringify(startManifest)})`
243
225
  }
244
226
 
245
227
  return undefined
@@ -18,7 +18,7 @@ export function routesManifestPlugin(): GeneratorPlugin {
18
18
  }
19
19
  const routesManifest = {
20
20
  [rootRouteId]: {
21
- filePath: rootRouteNode.filePath,
21
+ filePath: rootRouteNode.fullPath,
22
22
  children: routeTree.acc.routeTree.map((d) => d.routePath),
23
23
  },
24
24
  ...Object.fromEntries(
@@ -28,7 +28,7 @@ export function routesManifestPlugin(): GeneratorPlugin {
28
28
  return [
29
29
  filePathId,
30
30
  {
31
- filePath: d.filePath,
31
+ filePath: d.fullPath,
32
32
  parent: d.parent?.routePath ? d.parent.routePath : undefined,
33
33
  children: d.children?.map((childRoute) => childRoute.routePath),
34
34
  },
@@ -14,20 +14,44 @@ import {
14
14
  tanstackRouterAutoImport,
15
15
  tanstackRouterGenerator,
16
16
  } from '@tanstack/router-plugin/vite'
17
+ import { VITE_ENVIRONMENT_NAMES } from '../constants'
17
18
  import { routeTreeClientPlugin } from './route-tree-client-plugin'
18
19
  import { virtualRouteTreePlugin } from './virtual-route-tree-plugin'
19
20
  import { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'
20
21
  import { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'
21
22
  import type { PluginOption } from 'vite'
22
- import type { Config } from '@tanstack/router-generator'
23
+ import type { Config } from '@tanstack/router-plugin'
23
24
 
24
25
  export function tanStackStartRouter(config: Config): Array<PluginOption> {
25
26
  return [
26
27
  tanstackRouterGenerator({
27
28
  ...config,
28
29
  plugins: [serverRoutesPlugin(), routesManifestPlugin()],
30
+ plugin: {
31
+ vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },
32
+ },
33
+ }),
34
+ tanStackRouterCodeSplitter({
35
+ ...config,
36
+ codeSplittingOptions: {
37
+ ...config.codeSplittingOptions,
38
+ deleteNodes: ['ssr'],
39
+ addHmr: true,
40
+ },
41
+ plugin: {
42
+ vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },
43
+ },
44
+ }),
45
+ tanStackRouterCodeSplitter({
46
+ ...config,
47
+ codeSplittingOptions: {
48
+ ...config.codeSplittingOptions,
49
+ addHmr: false,
50
+ },
51
+ plugin: {
52
+ vite: { environmentName: VITE_ENVIRONMENT_NAMES.server },
53
+ },
29
54
  }),
30
- tanStackRouterCodeSplitter(config),
31
55
  tanstackRouterAutoImport(config),
32
56
  routeTreeClientPlugin(config),
33
57
  virtualRouteTreePlugin(config),
@@ -4,6 +4,7 @@ import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
4
4
  import { normalizePath } from 'vite'
5
5
  import { deadCodeElimination } from 'babel-dead-code-elimination'
6
6
  import { debug } from '../debug'
7
+ import { VITE_ENVIRONMENT_NAMES } from '../constants'
7
8
  import type { Plugin } from 'vite'
8
9
  import type { Config } from '@tanstack/router-generator'
9
10
 
@@ -19,7 +20,7 @@ export function routeTreeClientPlugin(config: Config): Plugin {
19
20
  name: 'tanstack-start:route-tree-client-plugin',
20
21
  enforce: 'pre',
21
22
  // only run this plugin in the client environment
22
- applyToEnvironment: (env) => env.config.consumer === 'client',
23
+ applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
23
24
  transform: {
24
25
  filter: { id: generatedRouteTreePath },
25
26
  handler(code, id) {
@@ -1,11 +1,10 @@
1
1
  import path from 'node:path'
2
2
  import { normalizePath } from 'vite'
3
+ import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
3
4
  import { debug } from '../debug'
4
5
  import type { Config } from '@tanstack/router-generator'
5
6
  import type { Plugin } from 'vite'
6
7
 
7
- export const moduleId = 'tanstack-start-route-tree:v'
8
-
9
8
  export function virtualRouteTreePlugin(config: Config): Plugin {
10
9
  const generatedRouteTreePath = normalizePath(
11
10
  path.resolve(config.generatedRouteTree),
@@ -16,10 +15,10 @@ export function virtualRouteTreePlugin(config: Config): Plugin {
16
15
  enforce: 'pre',
17
16
  sharedDuringBuild: true,
18
17
  resolveId: {
19
- filter: { id: new RegExp(moduleId) },
18
+ filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
20
19
  handler(id) {
21
20
  let resolvedId: string | null = null
22
- if (id === moduleId) {
21
+ if (id === VIRTUAL_MODULES.routeTree) {
23
22
  if (debug) console.info('resolving id', id, generatedRouteTreePath)
24
23
  resolvedId = generatedRouteTreePath
25
24
  }