@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,291 +1,16 @@
1
- import { createTanStackStartOptionsSchema } from './schema.js';
1
+ import { TanStackStartInputConfig } from './schema.js';
2
2
  import { PluginOption } from 'vite';
3
- import { z } from 'zod';
4
3
  import { CompileStartFrameworkOptions } from './compilers.js';
5
- export type TanStackStartInputConfig = z.input<ReturnType<typeof createTanStackStartOptionsSchema>>;
6
- export declare function getTanStackStartOptions(opts?: TanStackStartInputConfig): {
7
- tsr: {
8
- target: "react" | "solid";
9
- routeFileIgnorePrefix: string;
10
- routesDirectory: string;
11
- quoteStyle: "single" | "double";
12
- semicolons: boolean;
13
- disableLogging: boolean;
14
- routeTreeFileHeader: string[];
15
- indexToken: string;
16
- routeToken: string;
17
- generatedRouteTree: string;
18
- disableTypes: boolean;
19
- addExtensions: boolean;
20
- enableRouteTreeFormatting: boolean;
21
- routeTreeFileFooter: string[];
22
- tmpDir: string;
23
- virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
24
- routeFilePrefix?: string | undefined;
25
- routeFileIgnorePattern?: string | undefined;
26
- pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
27
- verboseFileRoutes?: boolean | undefined;
28
- autoCodeSplitting?: boolean | undefined;
29
- customScaffolding?: {
30
- routeTemplate?: string | undefined;
31
- lazyRouteTemplate?: string | undefined;
32
- } | undefined;
33
- experimental?: {
34
- enableCodeSplitting?: boolean | undefined;
35
- } | undefined;
36
- plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
37
- srcDirectory: string;
38
- };
39
- clientEntryPath: string;
40
- serverEntryPath: string;
41
- root: string;
42
- client: {
43
- base: string;
44
- entry?: string | undefined;
45
- };
46
- server: {
47
- entry?: string | undefined;
48
- };
49
- serverFns: {
50
- base: string;
51
- };
52
- public: {
53
- base: string;
54
- dir: string;
55
- };
56
- pages: {
57
- path: string;
58
- prerender?: {
59
- enabled?: boolean | undefined;
60
- outputPath?: string | undefined;
61
- autoSubfolderIndex?: boolean | undefined;
62
- crawlLinks?: boolean | undefined;
63
- retryCount?: number | undefined;
64
- retryDelay?: number | undefined;
65
- onSuccess?: ((args_0: {
66
- page: {
67
- path: string;
68
- sitemap?: {
69
- exclude?: boolean | undefined;
70
- priority?: number | undefined;
71
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never" | undefined;
72
- lastmod?: string | Date | undefined;
73
- alternateRefs?: {
74
- href: string;
75
- hreflang: string;
76
- }[] | undefined;
77
- images?: {
78
- loc: string;
79
- caption?: string | undefined;
80
- title?: string | undefined;
81
- }[] | undefined;
82
- news?: {
83
- title: string;
84
- publication: {
85
- name: string;
86
- language: string;
87
- };
88
- publicationDate: string | Date;
89
- } | undefined;
90
- } | undefined;
91
- fromCrawl?: boolean | undefined;
92
- };
93
- html: string;
94
- }, ...args: unknown[]) => any) | undefined;
95
- } | undefined;
96
- sitemap?: {
97
- exclude?: boolean | undefined;
98
- priority?: number | undefined;
99
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never" | undefined;
100
- lastmod?: string | Date | undefined;
101
- alternateRefs?: {
102
- href: string;
103
- hreflang: string;
104
- }[] | undefined;
105
- images?: {
106
- loc: string;
107
- caption?: string | undefined;
108
- title?: string | undefined;
109
- }[] | undefined;
110
- news?: {
111
- title: string;
112
- publication: {
113
- name: string;
114
- language: string;
115
- };
116
- publicationDate: string | Date;
117
- } | undefined;
118
- } | undefined;
119
- fromCrawl?: boolean | undefined;
120
- }[];
121
- target?: import('nitropack/presets').PresetNameInput | undefined;
122
- prerender?: ({
123
- filter?: ((args_0: {
124
- path: string;
125
- prerender?: {
126
- enabled?: boolean | undefined;
127
- outputPath?: string | undefined;
128
- autoSubfolderIndex?: boolean | undefined;
129
- crawlLinks?: boolean | undefined;
130
- retryCount?: number | undefined;
131
- retryDelay?: number | undefined;
132
- onSuccess?: ((args_0: {
133
- page: {
134
- path: string;
135
- sitemap?: {
136
- exclude?: boolean | undefined;
137
- priority?: number | undefined;
138
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never" | undefined;
139
- lastmod?: string | Date | undefined;
140
- alternateRefs?: {
141
- href: string;
142
- hreflang: string;
143
- }[] | undefined;
144
- images?: {
145
- loc: string;
146
- caption?: string | undefined;
147
- title?: string | undefined;
148
- }[] | undefined;
149
- news?: {
150
- title: string;
151
- publication: {
152
- name: string;
153
- language: string;
154
- };
155
- publicationDate: string | Date;
156
- } | undefined;
157
- } | undefined;
158
- fromCrawl?: boolean | undefined;
159
- };
160
- html: string;
161
- }, ...args: unknown[]) => any) | undefined;
162
- } | undefined;
163
- sitemap?: {
164
- exclude?: boolean | undefined;
165
- priority?: number | undefined;
166
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never" | undefined;
167
- lastmod?: string | Date | undefined;
168
- alternateRefs?: {
169
- href: string;
170
- hreflang: string;
171
- }[] | undefined;
172
- images?: {
173
- loc: string;
174
- caption?: string | undefined;
175
- title?: string | undefined;
176
- }[] | undefined;
177
- news?: {
178
- title: string;
179
- publication: {
180
- name: string;
181
- language: string;
182
- };
183
- publicationDate: string | Date;
184
- } | undefined;
185
- } | undefined;
186
- fromCrawl?: boolean | undefined;
187
- }, ...args: unknown[]) => any) | undefined;
188
- enabled?: boolean | undefined;
189
- concurrency?: number | undefined;
190
- failOnError?: boolean | undefined;
191
- } & {
192
- enabled?: boolean | undefined;
193
- outputPath?: string | undefined;
194
- autoSubfolderIndex?: boolean | undefined;
195
- crawlLinks?: boolean | undefined;
196
- retryCount?: number | undefined;
197
- retryDelay?: number | undefined;
198
- onSuccess?: ((args_0: {
199
- page: {
200
- path: string;
201
- sitemap?: {
202
- exclude?: boolean | undefined;
203
- priority?: number | undefined;
204
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never" | undefined;
205
- lastmod?: string | Date | undefined;
206
- alternateRefs?: {
207
- href: string;
208
- hreflang: string;
209
- }[] | undefined;
210
- images?: {
211
- loc: string;
212
- caption?: string | undefined;
213
- title?: string | undefined;
214
- }[] | undefined;
215
- news?: {
216
- title: string;
217
- publication: {
218
- name: string;
219
- language: string;
220
- };
221
- publicationDate: string | Date;
222
- } | undefined;
223
- } | undefined;
224
- fromCrawl?: boolean | undefined;
225
- };
226
- html: string;
227
- }, ...args: unknown[]) => any) | undefined;
228
- }) | undefined;
229
- sitemap?: {
230
- enabled: boolean;
231
- outputPath: string;
232
- host?: string | undefined;
233
- } | undefined;
234
- spa?: {
235
- prerender: {
236
- enabled: boolean;
237
- outputPath: string;
238
- autoSubfolderIndex?: boolean | undefined;
239
- crawlLinks: boolean;
240
- retryCount: number;
241
- retryDelay?: number | undefined;
242
- onSuccess?: ((args_0: {
243
- page: {
244
- path: string;
245
- sitemap?: {
246
- exclude?: boolean | undefined;
247
- priority?: number | undefined;
248
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never" | undefined;
249
- lastmod?: string | Date | undefined;
250
- alternateRefs?: {
251
- href: string;
252
- hreflang: string;
253
- }[] | undefined;
254
- images?: {
255
- loc: string;
256
- caption?: string | undefined;
257
- title?: string | undefined;
258
- }[] | undefined;
259
- news?: {
260
- title: string;
261
- publication: {
262
- name: string;
263
- language: string;
264
- };
265
- publicationDate: string | Date;
266
- } | undefined;
267
- } | undefined;
268
- fromCrawl?: boolean | undefined;
269
- };
270
- html: string;
271
- }, ...args: unknown[]) => any) | undefined;
272
- };
273
- enabled: boolean;
274
- maskPath: string;
275
- } | undefined;
276
- };
277
- export type TanStackStartOutputConfig = ReturnType<typeof getTanStackStartOptions>;
278
4
  export interface TanStackStartVitePluginCoreOptions {
279
5
  framework: CompileStartFrameworkOptions;
280
- getVirtualServerRootHandler: (ctx: {
281
- routerFilepath: string;
282
- serverEntryFilepath: string;
283
- }) => string;
284
- getVirtualServerEntry: (ctx: {
285
- routerFilepath: string;
286
- }) => string;
287
- getVirtualClientEntry: (ctx: {
288
- routerFilepath: string;
289
- }) => string;
6
+ defaultEntryPaths: {
7
+ client: string;
8
+ server: string;
9
+ };
10
+ crawlPackages?: (opts: {
11
+ name: string;
12
+ peerDependencies: Record<string, any>;
13
+ exports?: Record<string, any> | string;
14
+ }) => 'include' | 'exclude' | undefined;
290
15
  }
291
- export declare function TanStackStartVitePluginCore(opts: TanStackStartVitePluginCoreOptions, startConfig: TanStackStartOutputConfig): Array<PluginOption>;
16
+ export declare function TanStackStartVitePluginCore(corePluginOpts: TanStackStartVitePluginCoreOptions, startPluginOpts: TanStackStartInputConfig): Array<PluginOption>;
@@ -1,135 +1,211 @@
1
1
  import path from "node:path";
2
- import { createNitro } from "nitropack";
3
2
  import { trimPathRight } from "@tanstack/router-core";
4
3
  import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
5
4
  import { TanStackServerFnPluginEnv } from "@tanstack/server-functions-plugin";
6
5
  import * as vite from "vite";
7
- import { createTanStackConfig } from "./schema.js";
8
- import { nitroPlugin } from "./nitro-plugin/plugin.js";
6
+ import { crawlFrameworkPkgs } from "vitefu";
7
+ import { join } from "pathe";
9
8
  import { startManifestPlugin } from "./start-manifest-plugin/plugin.js";
10
9
  import { startCompilerPlugin } from "./start-compiler-plugin.js";
11
- import { SSR_ENTRY_FILE, VITE_ENVIRONMENT_NAMES, CLIENT_DIST_DIR } from "./constants.js";
10
+ import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from "./constants.js";
12
11
  import { tanStackStartRouter } from "./start-router-plugin/plugin.js";
13
12
  import { loadEnvPlugin } from "./load-env-plugin/plugin.js";
14
13
  import { devServerPlugin } from "./dev-server-plugin/plugin.js";
15
- import { resolveVirtualEntriesPlugin } from "./resolve-virtual-entries-plugin/plugin.js";
16
- createTanStackConfig();
17
- let ssrBundle;
18
- function TanStackStartVitePluginCore(opts, startConfig) {
14
+ import { parseStartConfig } from "./schema.js";
15
+ import { resolveEntry } from "./resolve-entries.js";
16
+ import { getServerOutputDirectory, getClientOutputDirectory } from "./output-directory.js";
17
+ import { postServerBuild } from "./post-server-build.js";
18
+ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
19
+ const startConfig = parseStartConfig(startPluginOpts);
20
+ const capturedBundle = {};
21
+ function getBundle(envName) {
22
+ const bundle = capturedBundle[envName];
23
+ if (!bundle) {
24
+ throw new Error(`No bundle captured for environment: ${envName}`);
25
+ }
26
+ return bundle;
27
+ }
19
28
  return [
20
29
  tanStackStartRouter({
21
30
  ...startConfig.tsr,
22
- target: opts.framework,
31
+ target: corePluginOpts.framework,
23
32
  autoCodeSplitting: true
24
33
  }),
25
- resolveVirtualEntriesPlugin(opts, startConfig),
26
34
  {
27
- name: "tanstack-start-core:config-client",
28
- async config(viteConfig) {
35
+ name: "tanstack-start-core:config",
36
+ async config(viteConfig, { command }) {
29
37
  const viteAppBase = trimPathRight(viteConfig.base || "/");
30
38
  globalThis.TSS_APP_BASE = viteAppBase;
31
- const nitroOutputPublicDir = await (async () => {
32
- const dummyNitroApp = await createNitro({
33
- preset: startConfig.target,
34
- compatibilityDate: "2024-12-01"
35
- });
36
- const nitroOutputPublicDir2 = dummyNitroApp.options.output.publicDir;
37
- await dummyNitroApp.close();
38
- return nitroOutputPublicDir2;
39
- })();
40
- const getClientEntryPath = (startConfig2) => {
41
- const entry = startConfig2.clientEntryPath.startsWith(
42
- "/~start/default-client-entry"
43
- ) ? startConfig2.clientEntryPath : vite.normalizePath(
44
- path.join(
45
- "/@fs",
46
- path.resolve(startConfig2.root, startConfig2.clientEntryPath)
47
- )
39
+ const root = viteConfig.root || process.cwd();
40
+ const resolvedSrcDirectory = join(root, startConfig.tsr.srcDirectory);
41
+ const routerFilePath = resolveEntry({
42
+ type: "router entry",
43
+ configuredEntry: startConfig.router.entry,
44
+ defaultEntry: "router",
45
+ root,
46
+ resolvedSrcDirectory,
47
+ required: true
48
+ });
49
+ const clientEntryPath = resolveEntry({
50
+ type: "client entry",
51
+ configuredEntry: startConfig.client.entry,
52
+ defaultEntry: "client",
53
+ root,
54
+ resolvedSrcDirectory,
55
+ required: false
56
+ });
57
+ const serverEntryPath = resolveEntry({
58
+ type: "server entry",
59
+ configuredEntry: startConfig.server.entry,
60
+ defaultEntry: "server",
61
+ root,
62
+ resolvedSrcDirectory,
63
+ required: false
64
+ });
65
+ let clientAlias;
66
+ if (clientEntryPath) {
67
+ clientAlias = vite.normalizePath(
68
+ path.join("/@fs", path.resolve(root, clientEntryPath))
48
69
  );
49
- return entry;
70
+ } else {
71
+ clientAlias = corePluginOpts.defaultEntryPaths.client;
72
+ }
73
+ let serverAlias;
74
+ if (serverEntryPath) {
75
+ serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath));
76
+ } else {
77
+ serverAlias = corePluginOpts.defaultEntryPaths.server;
78
+ }
79
+ const entryAliasConfiguration = {
80
+ [ENTRY_POINTS.router]: routerFilePath,
81
+ [ENTRY_POINTS.client]: clientAlias,
82
+ [ENTRY_POINTS.server]: serverAlias
83
+ };
84
+ const startPackageName = `@tanstack/${corePluginOpts.framework}-start`;
85
+ const routerPackageName = `@tanstack/${corePluginOpts.framework}-router`;
86
+ const additionalOptimizeDeps = {
87
+ include: /* @__PURE__ */ new Set(),
88
+ exclude: /* @__PURE__ */ new Set()
50
89
  };
90
+ const result = await crawlFrameworkPkgs({
91
+ root: process.cwd(),
92
+ isBuild: command === "build",
93
+ isFrameworkPkgByJson(pkgJson) {
94
+ if ([routerPackageName, startPackageName].includes(pkgJson.name)) {
95
+ return false;
96
+ }
97
+ const peerDependencies = pkgJson["peerDependencies"];
98
+ if (peerDependencies) {
99
+ const internalResult = corePluginOpts.crawlPackages?.({
100
+ name: pkgJson.name,
101
+ peerDependencies,
102
+ exports: pkgJson.exports
103
+ });
104
+ if (internalResult) {
105
+ if (internalResult === "exclude") {
106
+ additionalOptimizeDeps.exclude.add(pkgJson.name);
107
+ } else {
108
+ additionalOptimizeDeps.include.add(pkgJson.name);
109
+ }
110
+ }
111
+ return startPackageName in peerDependencies || routerPackageName in peerDependencies;
112
+ }
113
+ return false;
114
+ }
115
+ });
51
116
  return {
52
117
  base: viteAppBase,
118
+ // see https://vite.dev/config/shared-options.html#apptype
119
+ // this will prevent vite from injecting middlewares that we don't want
120
+ appType: viteConfig.appType ?? "custom",
53
121
  environments: {
54
122
  [VITE_ENVIRONMENT_NAMES.client]: {
55
123
  consumer: "client",
56
124
  build: {
57
- manifest: true,
125
+ emptyOutDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.client]?.build?.emptyOutDir ?? true,
58
126
  rollupOptions: {
59
127
  input: {
60
- main: getClientEntryPath(startConfig)
61
- },
62
- output: {
63
- dir: path.resolve(startConfig.root, CLIENT_DIST_DIR)
64
- },
65
- // TODO: this should be removed
66
- external: ["node:fs", "node:path", "node:os", "node:crypto"]
67
- }
128
+ main: ENTRY_POINTS.client
129
+ }
130
+ },
131
+ outDir: getClientOutputDirectory(viteConfig)
68
132
  }
69
133
  },
70
134
  [VITE_ENVIRONMENT_NAMES.server]: {
71
135
  consumer: "server",
72
136
  build: {
137
+ emptyOutDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.emptyOutDir ?? false,
73
138
  ssr: true,
74
- // we don't write to the file system as the below 'capture-output' plugin will
75
- // capture the output and write it to the virtual file system
76
- write: false,
77
- copyPublicDir: false,
78
139
  rollupOptions: {
79
- output: {
80
- entryFileNames: SSR_ENTRY_FILE
81
- },
82
- plugins: [
83
- {
84
- name: "capture-output",
85
- generateBundle(_options, bundle) {
86
- ssrBundle = bundle;
87
- }
88
- }
89
- ]
140
+ input: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.rollupOptions?.input ?? ENTRY_POINTS.server
90
141
  },
142
+ outDir: getServerOutputDirectory(viteConfig),
91
143
  commonjsOptions: {
92
144
  include: [/node_modules/]
93
- }
145
+ },
146
+ copyPublicDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.copyPublicDir ?? false
94
147
  }
95
148
  }
96
149
  },
97
150
  resolve: {
98
151
  noExternal: [
99
- "@tanstack/start-client",
100
- "@tanstack/start-client-core",
101
- "@tanstack/start-server",
102
- "@tanstack/start-server-core",
103
- "@tanstack/start-server-functions-fetcher",
104
- "@tanstack/start-server-functions-client",
105
- "@tanstack/start-server-functions-server",
106
- "@tanstack/start-router-manifest",
107
- "@tanstack/start-config",
108
- "@tanstack/server-functions-plugin",
109
- "nitropack",
110
- "@tanstack/**start**",
111
- ...Object.values(VIRTUAL_MODULES)
112
- ]
152
+ "@tanstack/start**",
153
+ `@tanstack/${corePluginOpts.framework}-start**`,
154
+ ...Object.values(VIRTUAL_MODULES),
155
+ startPackageName,
156
+ ...result.ssr.noExternal.sort()
157
+ ],
158
+ dedupe: [startPackageName],
159
+ alias: {
160
+ ...entryAliasConfiguration
161
+ }
113
162
  },
114
163
  optimizeDeps: {
115
- exclude: [...Object.values(VIRTUAL_MODULES)]
164
+ exclude: [
165
+ ...Object.values(VIRTUAL_MODULES),
166
+ startPackageName,
167
+ ...result.optimizeDeps.exclude.sort(),
168
+ ...additionalOptimizeDeps.exclude
169
+ ],
170
+ include: [...additionalOptimizeDeps.include]
116
171
  },
117
172
  /* prettier-ignore */
118
173
  define: {
119
174
  // define is an esbuild function that replaces the any instances of given keys with the given values
120
175
  // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify("TanStack Start")
121
176
  // This is not the same as injecting environment variables.
122
- ...defineReplaceEnv("TSS_CLIENT_ENTRY", getClientEntryPath(startConfig)),
123
- // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved
124
177
  ...defineReplaceEnv("TSS_SERVER_FN_BASE", startConfig.serverFns.base),
125
- ...defineReplaceEnv("TSS_OUTPUT_PUBLIC_DIR", nitroOutputPublicDir),
126
- ...defineReplaceEnv("TSS_APP_BASE", viteAppBase)
178
+ ...defineReplaceEnv("TSS_OUTPUT_PUBLIC_DIR", getClientOutputDirectory(viteConfig)),
179
+ ...defineReplaceEnv("TSS_APP_BASE", viteAppBase),
180
+ ...command === "serve" ? defineReplaceEnv("TSS_SHELL", startConfig.spa?.enabled ? "true" : "false") : {},
181
+ ...defineReplaceEnv("TSS_DEV_SERVER", command === "serve" ? "true" : "false")
182
+ },
183
+ builder: {
184
+ sharedPlugins: true,
185
+ async buildApp(builder) {
186
+ const client = builder.environments[VITE_ENVIRONMENT_NAMES.client];
187
+ const server = builder.environments[VITE_ENVIRONMENT_NAMES.server];
188
+ if (!client) {
189
+ throw new Error("Client environment not found");
190
+ }
191
+ if (!server) {
192
+ throw new Error("SSR environment not found");
193
+ }
194
+ if (!client.isBuilt) {
195
+ await builder.build(client);
196
+ }
197
+ if (!server.isBuilt) {
198
+ await builder.build(server);
199
+ }
200
+ const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server);
201
+ await postServerBuild({ builder, startConfig, serverBundle });
202
+ }
127
203
  }
128
204
  };
129
205
  }
130
206
  },
131
207
  // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv
132
- startCompilerPlugin(opts.framework, {
208
+ startCompilerPlugin(corePluginOpts.framework, {
133
209
  client: { envName: VITE_ENVIRONMENT_NAMES.client },
134
210
  server: { envName: VITE_ENVIRONMENT_NAMES.server }
135
211
  }),
@@ -137,29 +213,36 @@ function TanStackStartVitePluginCore(opts, startConfig) {
137
213
  // This is the ID that will be available to look up and import
138
214
  // our server function manifest and resolve its module
139
215
  manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,
140
- manifestOutputFilename: ".tanstack-start/build/server/server-functions-manifest.json",
141
216
  client: {
142
- getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
217
+ getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-client'`,
143
218
  replacer: (d) => `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,
144
219
  envName: VITE_ENVIRONMENT_NAMES.client
145
220
  },
146
221
  server: {
147
- getRuntimeCode: () => `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,
222
+ getRuntimeCode: () => `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-server'`,
148
223
  replacer: (d) => `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,
149
224
  envName: VITE_ENVIRONMENT_NAMES.server
225
+ }
226
+ }),
227
+ loadEnvPlugin(),
228
+ startManifestPlugin({
229
+ getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client)
230
+ }),
231
+ devServerPlugin({ startConfig }),
232
+ {
233
+ name: "tanstack-start:core:capture-bundle",
234
+ applyToEnvironment(e) {
235
+ return e.name === VITE_ENVIRONMENT_NAMES.client || e.name === VITE_ENVIRONMENT_NAMES.server;
150
236
  },
151
- importer: (fn) => {
152
- const serverEnv = globalThis.viteDevServer.environments[VITE_ENVIRONMENT_NAMES.server];
153
- if (!serverEnv) {
154
- throw new Error(`'ssr' vite dev environment not found`);
237
+ enforce: "post",
238
+ generateBundle(_options, bundle) {
239
+ const environment = this.environment.name;
240
+ if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {
241
+ throw new Error(`Unknown environment: ${environment}`);
155
242
  }
156
- return serverEnv.runner.import(fn.extractedFilename);
243
+ capturedBundle[environment] = bundle;
157
244
  }
158
- }),
159
- loadEnvPlugin(startConfig),
160
- startManifestPlugin(startConfig),
161
- devServerPlugin(),
162
- nitroPlugin(startConfig, () => ssrBundle)
245
+ }
163
246
  ];
164
247
  }
165
248
  function defineReplaceEnv(key, value) {