@tanstack/start-plugin-core 1.131.6 → 1.132.0-alpha.0

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