@tanstack/start-plugin-core 1.131.10 → 1.132.0-alpha.1

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 (145) 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 +2 -1
  15. package/dist/esm/index.js +2 -4
  16. package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
  17. package/dist/esm/load-env-plugin/plugin.js +5 -8
  18. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  19. package/dist/esm/output-directory.d.ts +3 -0
  20. package/dist/esm/output-directory.js +14 -0
  21. package/dist/esm/output-directory.js.map +1 -0
  22. package/dist/esm/plugin.d.ts +6 -290
  23. package/dist/esm/plugin.js +135 -76
  24. package/dist/esm/plugin.js.map +1 -1
  25. package/dist/esm/post-server-build.d.ts +7 -0
  26. package/dist/esm/post-server-build.js +55 -0
  27. package/dist/esm/post-server-build.js.map +1 -0
  28. package/dist/esm/prerender.d.ts +11 -0
  29. package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +85 -73
  30. package/dist/esm/prerender.js.map +1 -0
  31. package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
  32. package/dist/esm/queue.js.map +1 -0
  33. package/dist/esm/resolve-entries.d.ts +8 -0
  34. package/dist/esm/resolve-entries.js +37 -0
  35. package/dist/esm/resolve-entries.js.map +1 -0
  36. package/dist/esm/schema.d.ts +1369 -6719
  37. package/dist/esm/schema.js +52 -85
  38. package/dist/esm/schema.js.map +1 -1
  39. package/dist/esm/start-compiler-plugin.js +2 -2
  40. package/dist/esm/start-compiler-plugin.js.map +1 -1
  41. package/dist/esm/start-manifest-plugin/plugin.d.ts +1 -1
  42. package/dist/esm/start-manifest-plugin/plugin.js +8 -13
  43. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  44. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +2 -3
  45. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  46. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
  47. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
  48. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  49. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
  50. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
  51. package/dist/esm/utils.js.map +1 -1
  52. package/package.json +13 -18
  53. package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
  54. package/src/constants.ts +12 -9
  55. package/src/dev-server-plugin/plugin.ts +140 -99
  56. package/src/global.d.ts +0 -2
  57. package/src/index.ts +3 -5
  58. package/src/load-env-plugin/plugin.ts +6 -11
  59. package/src/output-directory.ts +18 -0
  60. package/src/plugin.ts +172 -98
  61. package/src/post-server-build.ts +73 -0
  62. package/src/{nitro-plugin/prerender.ts → prerender.ts} +93 -86
  63. package/src/resolve-entries.ts +52 -0
  64. package/src/schema.ts +88 -121
  65. package/src/start-manifest-plugin/plugin.ts +8 -14
  66. package/dist/cjs/compilers.cjs +0 -416
  67. package/dist/cjs/compilers.cjs.map +0 -1
  68. package/dist/cjs/compilers.d.cts +0 -21
  69. package/dist/cjs/constants.cjs +0 -20
  70. package/dist/cjs/constants.cjs.map +0 -1
  71. package/dist/cjs/constants.d.cts +0 -6
  72. package/dist/cjs/debug.cjs +0 -5
  73. package/dist/cjs/debug.cjs.map +0 -1
  74. package/dist/cjs/debug.d.cts +0 -1
  75. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
  76. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
  77. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
  78. package/dist/cjs/dev-server-plugin/plugin.cjs +0 -121
  79. package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
  80. package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
  81. package/dist/cjs/index.cjs +0 -11
  82. package/dist/cjs/index.cjs.map +0 -1
  83. package/dist/cjs/index.d.cts +0 -3
  84. package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
  85. package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
  86. package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
  87. package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
  88. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
  89. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
  90. package/dist/cjs/nitro-plugin/plugin.cjs +0 -187
  91. package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
  92. package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
  93. package/dist/cjs/nitro-plugin/prerender.cjs +0 -178
  94. package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
  95. package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
  96. package/dist/cjs/nitro-plugin/queue.cjs +0 -131
  97. package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
  98. package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
  99. package/dist/cjs/plugin.cjs +0 -227
  100. package/dist/cjs/plugin.cjs.map +0 -1
  101. package/dist/cjs/plugin.d.cts +0 -300
  102. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -80
  103. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
  104. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
  105. package/dist/cjs/schema.cjs +0 -158
  106. package/dist/cjs/schema.cjs.map +0 -1
  107. package/dist/cjs/schema.d.cts +0 -8878
  108. package/dist/cjs/start-compiler-plugin.cjs +0 -78
  109. package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
  110. package/dist/cjs/start-compiler-plugin.d.cts +0 -13
  111. package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
  112. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
  113. package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -6
  114. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
  115. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
  116. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
  117. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
  118. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
  119. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
  120. package/dist/cjs/start-router-plugin/plugin.cjs +0 -45
  121. package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
  122. package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
  123. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -73
  124. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
  125. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
  126. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -29
  127. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
  128. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -3
  129. package/dist/cjs/utils.cjs +0 -18
  130. package/dist/cjs/utils.cjs.map +0 -1
  131. package/dist/cjs/utils.d.cts +0 -8
  132. package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
  133. package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
  134. package/dist/esm/nitro-plugin/plugin.js +0 -187
  135. package/dist/esm/nitro-plugin/plugin.js.map +0 -1
  136. package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
  137. package/dist/esm/nitro-plugin/prerender.js.map +0 -1
  138. package/dist/esm/nitro-plugin/queue.js.map +0 -1
  139. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
  140. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -63
  141. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
  142. package/src/nitro-plugin/plugin.ts +0 -252
  143. package/src/resolve-virtual-entries-plugin/plugin.ts +0 -77
  144. /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
  145. /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,62 @@ 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
147
+ },
148
+ optimizeDeps: {
149
+ exclude: [
150
+ ...Object.values(VIRTUAL_MODULES),
151
+ ...result.optimizeDeps.exclude.sort(),
152
+ ...additionalOptimizeDeps.exclude,
153
+ `@tanstack/${corePluginOpts.framework}-start/server-functions-server`
154
+ ],
155
+ include: [
156
+ ...additionalOptimizeDeps.include,
157
+ ...result.optimizeDeps.include.sort()
158
+ ]
118
159
  }
119
160
  }
120
161
  },
121
162
  resolve: {
122
163
  noExternal: [
123
164
  "@tanstack/start**",
124
- `@tanstack/${opts.framework}-start**`,
165
+ `@tanstack/${corePluginOpts.framework}-start**`,
125
166
  ...Object.values(VIRTUAL_MODULES),
126
167
  startPackageName,
127
168
  ...result.ssr.noExternal.sort()
128
169
  ],
129
- external: [...result.ssr.external.sort()],
130
- dedupe: [startPackageName]
170
+ dedupe: [startPackageName],
171
+ alias: {
172
+ ...entryAliasConfiguration
173
+ }
131
174
  },
132
175
  optimizeDeps: {
133
176
  exclude: [
@@ -144,15 +187,37 @@ function TanStackStartVitePluginCore(opts, startConfig) {
144
187
  // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify("TanStack Start")
145
188
  // This is not the same as injecting environment variables.
146
189
  ...defineReplaceEnv("TSS_SERVER_FN_BASE", startConfig.serverFns.base),
147
- ...defineReplaceEnv("TSS_OUTPUT_PUBLIC_DIR", nitroOutputPublicDir),
190
+ ...defineReplaceEnv("TSS_OUTPUT_PUBLIC_DIR", getClientOutputDirectory(viteConfig)),
148
191
  ...defineReplaceEnv("TSS_APP_BASE", viteAppBase),
149
- ...command === "serve" ? defineReplaceEnv("TSS_SHELL", ((_a = startConfig.spa) == null ? void 0 : _a.enabled) ? "true" : "false") : {}
192
+ ...command === "serve" ? defineReplaceEnv("TSS_SHELL", startConfig.spa?.enabled ? "true" : "false") : {},
193
+ ...defineReplaceEnv("TSS_DEV_SERVER", command === "serve" ? "true" : "false")
194
+ },
195
+ builder: {
196
+ sharedPlugins: true,
197
+ async buildApp(builder) {
198
+ const client = builder.environments[VITE_ENVIRONMENT_NAMES.client];
199
+ const server = builder.environments[VITE_ENVIRONMENT_NAMES.server];
200
+ if (!client) {
201
+ throw new Error("Client environment not found");
202
+ }
203
+ if (!server) {
204
+ throw new Error("SSR environment not found");
205
+ }
206
+ if (!client.isBuilt) {
207
+ await builder.build(client);
208
+ }
209
+ if (!server.isBuilt) {
210
+ await builder.build(server);
211
+ }
212
+ const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server);
213
+ await postServerBuild({ builder, startConfig, serverBundle });
214
+ }
150
215
  }
151
216
  };
152
217
  }
153
218
  },
154
219
  // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv
155
- startCompilerPlugin(opts.framework, {
220
+ startCompilerPlugin(corePluginOpts.framework, {
156
221
  client: { envName: VITE_ENVIRONMENT_NAMES.client },
157
222
  server: { envName: VITE_ENVIRONMENT_NAMES.server }
158
223
  }),
@@ -161,28 +226,33 @@ function TanStackStartVitePluginCore(opts, startConfig) {
161
226
  // our server function manifest and resolve its module
162
227
  manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,
163
228
  client: {
164
- getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
229
+ getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-client'`,
165
230
  replacer: (d) => `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,
166
231
  envName: VITE_ENVIRONMENT_NAMES.client
167
232
  },
168
233
  server: {
169
- getRuntimeCode: () => `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,
234
+ getRuntimeCode: () => `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-server'`,
170
235
  replacer: (d) => `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,
171
236
  envName: VITE_ENVIRONMENT_NAMES.server
172
237
  }
173
238
  }),
174
- loadEnvPlugin(startConfig),
175
- startManifestPlugin({ clientEntry: getClientEntryPath(startConfig) }),
176
- devServerPlugin(),
177
- nitroPlugin(startConfig, () => ssrBundle),
239
+ loadEnvPlugin(),
240
+ startManifestPlugin({
241
+ getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client)
242
+ }),
243
+ devServerPlugin({ startConfig }),
178
244
  {
179
- name: "tanstack-start:core:capture-client-bundle",
245
+ name: "tanstack-start:core:capture-bundle",
180
246
  applyToEnvironment(e) {
181
- return e.name === VITE_ENVIRONMENT_NAMES.client;
247
+ return e.name === VITE_ENVIRONMENT_NAMES.client || e.name === VITE_ENVIRONMENT_NAMES.server;
182
248
  },
183
249
  enforce: "post",
184
250
  generateBundle(_options, bundle) {
185
- globalThis.TSS_CLIENT_BUNDLE = bundle;
251
+ const environment = this.environment.name;
252
+ if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {
253
+ throw new Error(`Unknown environment: ${environment}`);
254
+ }
255
+ capturedBundle[environment] = bundle;
186
256
  }
187
257
  }
188
258
  ];
@@ -193,17 +263,6 @@ function defineReplaceEnv(key, value) {
193
263
  [`import.meta.env.${key}`]: JSON.stringify(value)
194
264
  };
195
265
  }
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
266
  export {
208
267
  TanStackStartVitePluginCore
209
268
  };