@tanstack/start-plugin-core 1.121.0-alpha.26 → 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 -4
  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 -88
  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 -68
  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 -125
  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 -2
  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 -114
  68. package/src/post-server-build.ts +73 -0
  69. package/src/{nitro-plugin/prerender.ts → prerender.ts} +95 -79
  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 -165
  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 -14
  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 -170
  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 -191
  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 -207
  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,27 +1,21 @@
1
- import { mkdirSync, readFileSync, rmSync, writeFile } 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 type {
8
- PluginOption,
9
- ResolvedConfig,
10
- Manifest as ViteManifest,
11
- ManifestChunk as ViteManifestChunk,
12
- } from 'vite'
6
+ import { ENTRY_POINTS } from '../constants'
7
+ import type { PluginOption, Rollup } from 'vite'
13
8
  import type { RouterManagedTag } from '@tanstack/router-core'
14
- import type { TanStackStartOutputConfig } from '../plugin'
15
9
 
16
- const getCSSRecursively = (
17
- file: ViteManifestChunk,
18
- filesByRouteFilePath: ViteManifest,
10
+ export const getCSSRecursively = (
11
+ chunk: Rollup.OutputChunk,
12
+ chunksByFileName: Map<string, Rollup.OutputChunk>,
19
13
  basePath: string,
20
14
  ) => {
21
15
  const result: Array<RouterManagedTag> = []
22
16
 
23
17
  // Get all css imports from the file
24
- for (const cssFile of file.css ?? []) {
18
+ for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
25
19
  result.push({
26
20
  tag: 'link',
27
21
  attrs: {
@@ -33,11 +27,11 @@ const getCSSRecursively = (
33
27
  }
34
28
 
35
29
  // Recursively get CSS from imports
36
- for (const imp of file.imports ?? []) {
37
- const importInfo = filesByRouteFilePath[imp]
38
- if (importInfo) {
30
+ for (const importedFileName of chunk.imports) {
31
+ const importedChunk = chunksByFileName.get(importedFileName)
32
+ if (importedChunk) {
39
33
  result.push(
40
- ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),
34
+ ...getCSSRecursively(importedChunk, chunksByFileName, basePath),
41
35
  )
42
36
  }
43
37
  }
@@ -46,21 +40,12 @@ const getCSSRecursively = (
46
40
  }
47
41
 
48
42
  const resolvedModuleId = resolveViteId(VIRTUAL_MODULES.startManifest)
49
- export function startManifestPlugin(
50
- opts: TanStackStartOutputConfig,
51
- ): PluginOption {
52
- let config: ResolvedConfig
53
-
43
+ export function startManifestPlugin(opts: {
44
+ getClientBundle: () => Rollup.OutputBundle
45
+ }): PluginOption {
54
46
  return {
55
47
  name: 'tanstack-start:start-manifest-plugin',
56
48
  enforce: 'pre',
57
-
58
- configResolved(resolvedConfig) {
59
- config = resolvedConfig
60
- },
61
- // configEnvironment(env, envConfig) {
62
- // config = envConfig.
63
- // },
64
49
  resolveId: {
65
50
  filter: { id: new RegExp(VIRTUAL_MODULES.startManifest) },
66
51
  handler(id) {
@@ -82,129 +67,129 @@ export function startManifestPlugin(
82
67
  return `export default {}`
83
68
  }
84
69
 
85
- // If we're in development, return a dummy manifest
86
- if (config.command === 'serve') {
87
- return `export const tsrStartManifest = () => ({
88
- routes: {}
89
- })`
90
- }
91
-
92
70
  // This is the basepath for the application
93
71
  const APP_BASE = globalThis.TSS_APP_BASE
94
72
 
95
- const clientViteManifestPath = path.resolve(
96
- opts.root,
97
- '.tanstack-start/build/client-dist/.vite/manifest.json',
98
- )
99
-
100
- let viteManifest: ViteManifest
101
- try {
102
- viteManifest = JSON.parse(
103
- readFileSync(clientViteManifestPath, 'utf-8'),
104
- )
105
- } catch (err) {
106
- console.error(err)
107
- throw new Error(
108
- `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,
109
- )
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
+ })`
110
79
  }
111
80
 
112
81
  // This the manifest pulled from the generated route tree and later used by the Router.
113
- // i.e what's located in `src/generatedRouteTree.gen.ts`
82
+ // i.e what's located in `src/routeTree.gen.ts`
114
83
  const routeTreeRoutes = globalThis.TSS_ROUTES_MANIFEST.routes
115
84
 
116
85
  // This is where hydration will start, from when the SSR'd page reaches the browser.
117
- // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.
118
- let entryFile: ViteManifestChunk | undefined
119
-
120
- const filesByRouteFilePath: ViteManifest = Object.fromEntries(
121
- Object.entries(viteManifest).map(([k, v]) => {
122
- if (v.isEntry) {
123
- if (entryFile !== undefined) {
124
- console.error(
125
- `multiple entries detected`,
126
- entryFile.file,
127
- 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}`,
128
102
  )
129
103
  }
130
- entryFile = v
104
+ entryFile = bundleEntry
131
105
  }
132
-
133
- const rPath = k.split('?')[0]
134
-
135
- return [rPath, v]
136
- }, {}),
137
- )
138
-
139
- const routesDirectoryFromRoot = path.relative(
140
- opts.root,
141
- opts.tsr.routesDirectory,
142
- )
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
+ }
143
137
 
144
138
  // Add preloads to the routes from the vite manifest
145
139
  Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {
146
- const file =
147
- filesByRouteFilePath[
148
- path.posix.join(routesDirectoryFromRoot, v.filePath as string)
149
- ]
150
-
151
- if (file) {
152
- // Map the relevant imports to their route paths,
153
- // so that it can be imported in the browser.
154
- const preloads = (file.imports ?? []).map((d) => {
155
- const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)
156
- 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
+ }
157
169
  })
158
-
159
- // Since this is the most important JS entry for the route,
160
- // it should be moved to the front of the preloads so that
161
- // it has the best chance of being loaded first.
162
- if (file.file) {
163
- preloads.unshift(path.join(APP_BASE, file.file))
164
- }
165
-
166
- const cssAssetsList = getCSSRecursively(
167
- file,
168
- filesByRouteFilePath,
169
- APP_BASE,
170
- )
171
-
172
- routeTreeRoutes[routeId] = {
173
- ...v,
174
- assets: [...(v.assets || []), ...cssAssetsList],
175
- preloads,
176
- }
177
170
  }
178
171
  })
179
172
 
180
- if (entryFile) {
181
- routeTreeRoutes[rootRouteId]!.preloads = [
182
- joinURL(APP_BASE, entryFile.file),
183
- ...(entryFile.imports?.map((d) =>
184
- joinURL(APP_BASE, viteManifest[d]!.file),
185
- ) || []),
186
- ]
187
-
188
- // Gather all the CSS files from the entry file in
189
- // the `css` key and add them to the root route
190
- const entryCssAssetsList = getCSSRecursively(
191
- entryFile,
192
- filesByRouteFilePath,
193
- APP_BASE,
194
- )
195
-
196
- routeTreeRoutes[rootRouteId]!.assets = [
197
- ...(routeTreeRoutes[rootRouteId]!.assets || []),
198
- ...entryCssAssetsList,
199
- {
200
- tag: 'script',
201
- attrs: {
202
- src: joinURL(APP_BASE, entryFile.file),
203
- type: 'module',
204
- },
205
- },
206
- ]
173
+ if (!entryFile) {
174
+ throw new Error('No entry file found')
207
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
+ ]
208
193
 
209
194
  const recurseRoute = (
210
195
  route: {
@@ -229,43 +214,14 @@ export function startManifestPlugin(
229
214
  }
230
215
  }
231
216
 
232
- // @ts-expect-error
233
- recurseRoute(routeTreeRoutes[rootRouteId])
217
+ recurseRoute(routeTreeRoutes[rootRouteId]!)
234
218
 
235
- const routesManifest = {
219
+ const startManifest = {
236
220
  routes: routeTreeRoutes,
221
+ clientEntry: joinURL(APP_BASE, entryFile.fileName),
237
222
  }
238
223
 
239
- try {
240
- const routesManifestOutputDirPath = path.resolve(
241
- opts.root,
242
- '.tanstack-start/build/route-assets-manifest',
243
- )
244
- rmSync(routesManifestOutputDirPath, {
245
- recursive: true,
246
- force: true,
247
- })
248
- mkdirSync(routesManifestOutputDirPath, { recursive: true })
249
- writeFile(
250
- path.join(routesManifestOutputDirPath, 'manifest.json'),
251
- JSON.stringify(routesManifest),
252
- (err) => {
253
- if (err) {
254
- console.error(
255
- 'There was an error writing the routes manifest to disk.\nYou can ignore this error. It does not affect the runtime of your application.',
256
- )
257
- console.error(err)
258
- }
259
- },
260
- )
261
- } catch (err) {
262
- console.error(
263
- 'There was an error writing the routes manifest to disk.\nYou can ignore this error. It does not affect the runtime of your application.',
264
- )
265
- console.error(err)
266
- }
267
-
268
- return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`
224
+ return `export const tsrStartManifest = () => (${JSON.stringify(startManifest)})`
269
225
  }
270
226
 
271
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
  }