@tanstack/start-plugin-core 1.166.11 → 1.166.13
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.
- package/dist/esm/build-sitemap.js +94 -123
- package/dist/esm/build-sitemap.js.map +1 -1
- package/dist/esm/constants.js +15 -20
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/dev-server-plugin/dev-styles.js +137 -150
- package/dist/esm/dev-server-plugin/dev-styles.js.map +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js +16 -15
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
- package/dist/esm/dev-server-plugin/plugin.js +125 -195
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/ast.js +6 -5
- package/dist/esm/import-protection-plugin/ast.js.map +1 -1
- package/dist/esm/import-protection-plugin/constants.js +20 -22
- package/dist/esm/import-protection-plugin/constants.js.map +1 -1
- package/dist/esm/import-protection-plugin/defaults.js +35 -25
- package/dist/esm/import-protection-plugin/defaults.js.map +1 -1
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +93 -92
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +1 -1
- package/dist/esm/import-protection-plugin/matchers.js +23 -24
- package/dist/esm/import-protection-plugin/matchers.js.map +1 -1
- package/dist/esm/import-protection-plugin/plugin.js +1045 -1361
- package/dist/esm/import-protection-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/postCompileUsage.js +58 -55
- package/dist/esm/import-protection-plugin/postCompileUsage.js.map +1 -1
- package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +187 -259
- package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +1 -1
- package/dist/esm/import-protection-plugin/sourceLocation.js +238 -248
- package/dist/esm/import-protection-plugin/sourceLocation.js.map +1 -1
- package/dist/esm/import-protection-plugin/trace.js +173 -184
- package/dist/esm/import-protection-plugin/trace.js.map +1 -1
- package/dist/esm/import-protection-plugin/utils.js +132 -111
- package/dist/esm/import-protection-plugin/utils.js.map +1 -1
- package/dist/esm/import-protection-plugin/virtualModules.js +214 -194
- package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -1
- package/dist/esm/index.js +2 -7
- package/dist/esm/load-env-plugin/plugin.js +12 -11
- package/dist/esm/load-env-plugin/plugin.js.map +1 -1
- package/dist/esm/output-directory.js +10 -10
- package/dist/esm/output-directory.js.map +1 -1
- package/dist/esm/plugin.js +275 -355
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/post-server-build.js +39 -53
- package/dist/esm/post-server-build.js.map +1 -1
- package/dist/esm/prerender.js +177 -239
- package/dist/esm/prerender.js.map +1 -1
- package/dist/esm/preview-server-plugin/plugin.js +41 -44
- package/dist/esm/preview-server-plugin/plugin.js.map +1 -1
- package/dist/esm/queue.js +115 -126
- package/dist/esm/queue.js.map +1 -1
- package/dist/esm/resolve-entries.js +31 -32
- package/dist/esm/resolve-entries.js.map +1 -1
- package/dist/esm/schema.js +156 -179
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compiler.js +655 -812
- package/dist/esm/start-compiler-plugin/compiler.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js +25 -8
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js +22 -19
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js +20 -22
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js +187 -255
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js +23 -33
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +1 -1
- package/dist/esm/start-compiler-plugin/plugin.js +247 -291
- package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
- package/dist/esm/start-compiler-plugin/utils.js +27 -27
- package/dist/esm/start-compiler-plugin/utils.js.map +1 -1
- package/dist/esm/start-manifest-plugin/manifestBuilder.js +272 -378
- package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +35 -44
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/constants.js +6 -5
- package/dist/esm/start-router-plugin/constants.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js +24 -19
- package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +28 -29
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.js +146 -199
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +32 -31
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -1
- package/dist/esm/utils.js +14 -14
- package/dist/esm/utils.js.map +1 -1
- package/package.json +7 -7
- package/dist/esm/index.js.map +0 -1
package/dist/esm/plugin.js
CHANGED
|
@@ -1,371 +1,291 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as vite from "vite";
|
|
3
|
-
import { crawlFrameworkPkgs } from "vitefu";
|
|
4
|
-
import { join } from "pathe";
|
|
5
|
-
import { escapePath } from "tinyglobby";
|
|
1
|
+
import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from "./constants.js";
|
|
6
2
|
import { startManifestPlugin } from "./start-manifest-plugin/plugin.js";
|
|
7
|
-
import { VITE_ENVIRONMENT_NAMES, ENTRY_POINTS } from "./constants.js";
|
|
8
3
|
import { tanStackStartRouter } from "./start-router-plugin/plugin.js";
|
|
9
4
|
import { loadEnvPlugin } from "./load-env-plugin/plugin.js";
|
|
10
5
|
import { devServerPlugin } from "./dev-server-plugin/plugin.js";
|
|
6
|
+
import { getClientOutputDirectory, getServerOutputDirectory } from "./output-directory.js";
|
|
11
7
|
import { previewServerPlugin } from "./preview-server-plugin/plugin.js";
|
|
12
8
|
import { parseStartConfig } from "./schema.js";
|
|
13
9
|
import { resolveEntry } from "./resolve-entries.js";
|
|
14
|
-
import { getServerOutputDirectory, getClientOutputDirectory } from "./output-directory.js";
|
|
15
10
|
import { postServerBuild } from "./post-server-build.js";
|
|
16
11
|
import { startCompilerPlugin } from "./start-compiler-plugin/plugin.js";
|
|
17
12
|
import { importProtectionPlugin } from "./import-protection-plugin/plugin.js";
|
|
13
|
+
import { joinPaths } from "@tanstack/router-core";
|
|
14
|
+
import * as vite from "vite";
|
|
15
|
+
import { crawlFrameworkPkgs } from "vitefu";
|
|
16
|
+
import { join } from "pathe";
|
|
17
|
+
import { escapePath } from "tinyglobby";
|
|
18
|
+
//#region src/plugin.ts
|
|
18
19
|
function isFullUrl(str) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
try {
|
|
21
|
+
new URL(str);
|
|
22
|
+
return true;
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
27
|
function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
},
|
|
281
|
-
// Separate plugin for buildApp hook with enforce: 'post'
|
|
282
|
-
// This ensures proper ordering with other plugins that also have
|
|
283
|
-
// buildApp hooks with order: 'post'. The enforce: 'post' ensures this
|
|
284
|
-
// runs after other plugins (like Nitro) complete their builds.
|
|
285
|
-
{
|
|
286
|
-
name: "tanstack-start-core:post-build",
|
|
287
|
-
enforce: "post",
|
|
288
|
-
buildApp: {
|
|
289
|
-
order: "post",
|
|
290
|
-
async handler(builder) {
|
|
291
|
-
const { startConfig: startConfig2 } = getConfig();
|
|
292
|
-
await postServerBuild({ builder, startConfig: startConfig2 });
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
// Server function plugin handles:
|
|
297
|
-
// 1. Identifying createServerFn().handler() calls
|
|
298
|
-
// 2. Extracting server functions to separate modules
|
|
299
|
-
// 3. Replacing call sites with RPC stubs
|
|
300
|
-
// 4. Generating the server function manifest
|
|
301
|
-
// Also handles createIsomorphicFn, createServerOnlyFn, createClientOnlyFn, createMiddleware
|
|
302
|
-
startCompilerPlugin({
|
|
303
|
-
framework: corePluginOpts.framework,
|
|
304
|
-
environments,
|
|
305
|
-
generateFunctionId: startPluginOpts?.serverFns?.generateFunctionId,
|
|
306
|
-
providerEnvName: serverFnProviderEnv
|
|
307
|
-
}),
|
|
308
|
-
importProtectionPlugin({
|
|
309
|
-
getConfig,
|
|
310
|
-
framework: corePluginOpts.framework,
|
|
311
|
-
environments,
|
|
312
|
-
providerEnvName: serverFnProviderEnv
|
|
313
|
-
}),
|
|
314
|
-
tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),
|
|
315
|
-
loadEnvPlugin(),
|
|
316
|
-
startManifestPlugin({
|
|
317
|
-
getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),
|
|
318
|
-
getConfig
|
|
319
|
-
}),
|
|
320
|
-
// When the vite base and router basepath are misaligned (e.g. base: '/_ui/', basepath: '/'),
|
|
321
|
-
// install a middleware that rewrites incoming request URLs to prepend the vite base prefix.
|
|
322
|
-
// This allows Vite's internal base middleware to accept the requests, then strips the prefix
|
|
323
|
-
// before passing to the SSR handler.
|
|
324
|
-
// Registered BEFORE devServerPlugin so this middleware is added to the Connect stack first,
|
|
325
|
-
// ensuring all subsequent middlewares (CSS, SSR, etc.) see the rewritten URL.
|
|
326
|
-
{
|
|
327
|
-
name: "tanstack-start-core:dev-base-rewrite",
|
|
328
|
-
configureServer(server) {
|
|
329
|
-
if (!needsDevBaseRewrite) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const basePrefix = resolvedStartConfig.viteAppBase.replace(/\/$/, "");
|
|
333
|
-
server.middlewares.use((req, _res, next) => {
|
|
334
|
-
if (req.url && !req.url.startsWith(basePrefix)) {
|
|
335
|
-
req.url = basePrefix + req.url;
|
|
336
|
-
}
|
|
337
|
-
next();
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
devServerPlugin({
|
|
342
|
-
getConfig,
|
|
343
|
-
devSsrStylesEnabled: startPluginOpts?.dev?.ssrStyles?.enabled ?? true
|
|
344
|
-
}),
|
|
345
|
-
previewServerPlugin(),
|
|
346
|
-
{
|
|
347
|
-
name: "tanstack-start:core:capture-bundle",
|
|
348
|
-
applyToEnvironment(e) {
|
|
349
|
-
return e.name === VITE_ENVIRONMENT_NAMES.client || e.name === VITE_ENVIRONMENT_NAMES.server;
|
|
350
|
-
},
|
|
351
|
-
enforce: "post",
|
|
352
|
-
generateBundle(_options, bundle) {
|
|
353
|
-
const environment = this.environment.name;
|
|
354
|
-
if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {
|
|
355
|
-
throw new Error(`Unknown environment: ${environment}`);
|
|
356
|
-
}
|
|
357
|
-
capturedBundle[environment] = bundle;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
];
|
|
28
|
+
const serverFnProviderEnv = corePluginOpts.serverFn?.providerEnv || VITE_ENVIRONMENT_NAMES.server;
|
|
29
|
+
const ssrIsProvider = serverFnProviderEnv === VITE_ENVIRONMENT_NAMES.server;
|
|
30
|
+
const resolvedStartConfig = {
|
|
31
|
+
root: "",
|
|
32
|
+
startFilePath: void 0,
|
|
33
|
+
routerFilePath: "",
|
|
34
|
+
srcDirectory: "",
|
|
35
|
+
viteAppBase: "",
|
|
36
|
+
serverFnProviderEnv
|
|
37
|
+
};
|
|
38
|
+
let startConfig;
|
|
39
|
+
const getConfig = () => {
|
|
40
|
+
if (!resolvedStartConfig.root) throw new Error(`Cannot get config before root is resolved`);
|
|
41
|
+
if (!startConfig) startConfig = parseStartConfig(startPluginOpts, corePluginOpts, resolvedStartConfig.root);
|
|
42
|
+
return {
|
|
43
|
+
startConfig,
|
|
44
|
+
resolvedStartConfig,
|
|
45
|
+
corePluginOpts
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
let needsDevBaseRewrite = false;
|
|
49
|
+
const capturedBundle = {};
|
|
50
|
+
function getBundle(envName) {
|
|
51
|
+
const bundle = capturedBundle[envName];
|
|
52
|
+
if (!bundle) throw new Error(`No bundle captured for environment: ${envName}`);
|
|
53
|
+
return bundle;
|
|
54
|
+
}
|
|
55
|
+
const environments = [{
|
|
56
|
+
name: VITE_ENVIRONMENT_NAMES.client,
|
|
57
|
+
type: "client"
|
|
58
|
+
}, {
|
|
59
|
+
name: VITE_ENVIRONMENT_NAMES.server,
|
|
60
|
+
type: "server"
|
|
61
|
+
}];
|
|
62
|
+
if (corePluginOpts.serverFn?.providerEnv && !environments.find((e) => e.name === corePluginOpts.serverFn?.providerEnv)) environments.push({
|
|
63
|
+
name: corePluginOpts.serverFn.providerEnv,
|
|
64
|
+
type: "server"
|
|
65
|
+
});
|
|
66
|
+
return [
|
|
67
|
+
{
|
|
68
|
+
name: "tanstack-start-core:config",
|
|
69
|
+
enforce: "pre",
|
|
70
|
+
async config(viteConfig, { command }) {
|
|
71
|
+
resolvedStartConfig.viteAppBase = viteConfig.base ?? "/";
|
|
72
|
+
if (!isFullUrl(resolvedStartConfig.viteAppBase)) resolvedStartConfig.viteAppBase = joinPaths([
|
|
73
|
+
"/",
|
|
74
|
+
viteConfig.base,
|
|
75
|
+
"/"
|
|
76
|
+
]);
|
|
77
|
+
const root = viteConfig.root || process.cwd();
|
|
78
|
+
resolvedStartConfig.root = root;
|
|
79
|
+
const { startConfig } = getConfig();
|
|
80
|
+
if (startConfig.router.basepath === void 0) if (!isFullUrl(resolvedStartConfig.viteAppBase)) startConfig.router.basepath = resolvedStartConfig.viteAppBase.replace(/^\/|\/$/g, "");
|
|
81
|
+
else startConfig.router.basepath = "/";
|
|
82
|
+
else if (command === "serve" && !viteConfig.server?.middlewareMode) {
|
|
83
|
+
if (!joinPaths([
|
|
84
|
+
"/",
|
|
85
|
+
startConfig.router.basepath,
|
|
86
|
+
"/"
|
|
87
|
+
]).startsWith(joinPaths([
|
|
88
|
+
"/",
|
|
89
|
+
resolvedStartConfig.viteAppBase,
|
|
90
|
+
"/"
|
|
91
|
+
]))) needsDevBaseRewrite = true;
|
|
92
|
+
}
|
|
93
|
+
const TSS_SERVER_FN_BASE = joinPaths([
|
|
94
|
+
"/",
|
|
95
|
+
startConfig.router.basepath,
|
|
96
|
+
startConfig.serverFns.base,
|
|
97
|
+
"/"
|
|
98
|
+
]);
|
|
99
|
+
const resolvedSrcDirectory = join(root, startConfig.srcDirectory);
|
|
100
|
+
resolvedStartConfig.srcDirectory = resolvedSrcDirectory;
|
|
101
|
+
const startFilePath = resolveEntry({
|
|
102
|
+
type: "start entry",
|
|
103
|
+
configuredEntry: startConfig.start.entry,
|
|
104
|
+
defaultEntry: "start",
|
|
105
|
+
resolvedSrcDirectory,
|
|
106
|
+
required: false
|
|
107
|
+
});
|
|
108
|
+
resolvedStartConfig.startFilePath = startFilePath;
|
|
109
|
+
const routerFilePath = resolveEntry({
|
|
110
|
+
type: "router entry",
|
|
111
|
+
configuredEntry: startConfig.router.entry,
|
|
112
|
+
defaultEntry: "router",
|
|
113
|
+
resolvedSrcDirectory,
|
|
114
|
+
required: true
|
|
115
|
+
});
|
|
116
|
+
resolvedStartConfig.routerFilePath = routerFilePath;
|
|
117
|
+
const clientEntryPath = resolveEntry({
|
|
118
|
+
type: "client entry",
|
|
119
|
+
configuredEntry: startConfig.client.entry,
|
|
120
|
+
defaultEntry: "client",
|
|
121
|
+
resolvedSrcDirectory,
|
|
122
|
+
required: false
|
|
123
|
+
});
|
|
124
|
+
const serverEntryPath = resolveEntry({
|
|
125
|
+
type: "server entry",
|
|
126
|
+
configuredEntry: startConfig.server.entry,
|
|
127
|
+
defaultEntry: "server",
|
|
128
|
+
resolvedSrcDirectory,
|
|
129
|
+
required: false
|
|
130
|
+
});
|
|
131
|
+
const clientAlias = vite.normalizePath(clientEntryPath ?? corePluginOpts.defaultEntryPaths.client);
|
|
132
|
+
const serverAlias = vite.normalizePath(serverEntryPath ?? corePluginOpts.defaultEntryPaths.server);
|
|
133
|
+
const startAlias = vite.normalizePath(startFilePath ?? corePluginOpts.defaultEntryPaths.start);
|
|
134
|
+
const routerAlias = vite.normalizePath(routerFilePath);
|
|
135
|
+
const entryAliasConfiguration = {
|
|
136
|
+
[ENTRY_POINTS.client]: clientAlias,
|
|
137
|
+
[ENTRY_POINTS.server]: serverAlias,
|
|
138
|
+
[ENTRY_POINTS.start]: startAlias,
|
|
139
|
+
[ENTRY_POINTS.router]: routerAlias
|
|
140
|
+
};
|
|
141
|
+
const startPackageName = `@tanstack/${corePluginOpts.framework}-start`;
|
|
142
|
+
const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({
|
|
143
|
+
root: process.cwd(),
|
|
144
|
+
isBuild: command === "build",
|
|
145
|
+
isFrameworkPkgByJson(pkgJson) {
|
|
146
|
+
const peerDependencies = pkgJson["peerDependencies"];
|
|
147
|
+
if (peerDependencies) {
|
|
148
|
+
if (startPackageName in peerDependencies || "@tanstack/start-client-core" in peerDependencies) return true;
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
appType: viteConfig.appType ?? "custom",
|
|
155
|
+
environments: {
|
|
156
|
+
[VITE_ENVIRONMENT_NAMES.client]: {
|
|
157
|
+
consumer: "client",
|
|
158
|
+
build: {
|
|
159
|
+
rollupOptions: { input: { main: ENTRY_POINTS.client } },
|
|
160
|
+
outDir: getClientOutputDirectory(viteConfig)
|
|
161
|
+
},
|
|
162
|
+
optimizeDeps: {
|
|
163
|
+
exclude: crawlFrameworkPkgsResult.optimizeDeps.exclude,
|
|
164
|
+
entries: [clientAlias, routerAlias].map((entry) => escapePath(entry))
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
[VITE_ENVIRONMENT_NAMES.server]: {
|
|
168
|
+
consumer: "server",
|
|
169
|
+
build: {
|
|
170
|
+
ssr: true,
|
|
171
|
+
rollupOptions: { input: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.rollupOptions?.input ?? serverAlias },
|
|
172
|
+
outDir: getServerOutputDirectory(viteConfig),
|
|
173
|
+
commonjsOptions: { include: [/node_modules/] },
|
|
174
|
+
copyPublicDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.copyPublicDir ?? false
|
|
175
|
+
},
|
|
176
|
+
optimizeDeps: { entries: [
|
|
177
|
+
serverAlias,
|
|
178
|
+
startAlias,
|
|
179
|
+
routerAlias
|
|
180
|
+
].map((entry) => escapePath(entry)) }
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
resolve: {
|
|
184
|
+
noExternal: [
|
|
185
|
+
"@tanstack/start**",
|
|
186
|
+
`@tanstack/${corePluginOpts.framework}-start**`,
|
|
187
|
+
...crawlFrameworkPkgsResult.ssr.noExternal.sort()
|
|
188
|
+
],
|
|
189
|
+
alias: { ...entryAliasConfiguration }
|
|
190
|
+
},
|
|
191
|
+
define: {
|
|
192
|
+
...defineReplaceEnv("TSS_SERVER_FN_BASE", TSS_SERVER_FN_BASE),
|
|
193
|
+
...defineReplaceEnv("TSS_CLIENT_OUTPUT_DIR", getClientOutputDirectory(viteConfig)),
|
|
194
|
+
...defineReplaceEnv("TSS_ROUTER_BASEPATH", startConfig.router.basepath),
|
|
195
|
+
...command === "serve" ? defineReplaceEnv("TSS_SHELL", startConfig.spa?.enabled ? "true" : "false") : {},
|
|
196
|
+
...defineReplaceEnv("TSS_DEV_SERVER", command === "serve" ? "true" : "false"),
|
|
197
|
+
...defineReplaceEnv("TSS_DEV_SSR_STYLES_ENABLED", startConfig.dev.ssrStyles.enabled ? "true" : "false"),
|
|
198
|
+
...defineReplaceEnv("TSS_DEV_SSR_STYLES_BASEPATH", startConfig.dev.ssrStyles.basepath ?? resolvedStartConfig.viteAppBase),
|
|
199
|
+
...command === "build" && startConfig.server.build.staticNodeEnv ? { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || viteConfig.mode || "production") } : {}
|
|
200
|
+
},
|
|
201
|
+
builder: {
|
|
202
|
+
sharedPlugins: true,
|
|
203
|
+
async buildApp(builder) {
|
|
204
|
+
const client = builder.environments[VITE_ENVIRONMENT_NAMES.client];
|
|
205
|
+
const server = builder.environments[VITE_ENVIRONMENT_NAMES.server];
|
|
206
|
+
if (!client) throw new Error("Client environment not found");
|
|
207
|
+
if (!server) throw new Error("SSR environment not found");
|
|
208
|
+
if (!client.isBuilt) await builder.build(client);
|
|
209
|
+
if (!server.isBuilt) await builder.build(server);
|
|
210
|
+
if (!ssrIsProvider) {
|
|
211
|
+
const providerEnv = builder.environments[serverFnProviderEnv];
|
|
212
|
+
if (!providerEnv) throw new Error(`Provider environment "${serverFnProviderEnv}" not found`);
|
|
213
|
+
if (!providerEnv.isBuilt) await builder.build(providerEnv);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
name: "tanstack-start-core:post-build",
|
|
222
|
+
enforce: "post",
|
|
223
|
+
buildApp: {
|
|
224
|
+
order: "post",
|
|
225
|
+
async handler(builder) {
|
|
226
|
+
const { startConfig } = getConfig();
|
|
227
|
+
await postServerBuild({
|
|
228
|
+
builder,
|
|
229
|
+
startConfig
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
startCompilerPlugin({
|
|
235
|
+
framework: corePluginOpts.framework,
|
|
236
|
+
environments,
|
|
237
|
+
generateFunctionId: startPluginOpts?.serverFns?.generateFunctionId,
|
|
238
|
+
providerEnvName: serverFnProviderEnv
|
|
239
|
+
}),
|
|
240
|
+
importProtectionPlugin({
|
|
241
|
+
getConfig,
|
|
242
|
+
framework: corePluginOpts.framework,
|
|
243
|
+
environments,
|
|
244
|
+
providerEnvName: serverFnProviderEnv
|
|
245
|
+
}),
|
|
246
|
+
tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),
|
|
247
|
+
loadEnvPlugin(),
|
|
248
|
+
startManifestPlugin({
|
|
249
|
+
getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),
|
|
250
|
+
getConfig
|
|
251
|
+
}),
|
|
252
|
+
{
|
|
253
|
+
name: "tanstack-start-core:dev-base-rewrite",
|
|
254
|
+
configureServer(server) {
|
|
255
|
+
if (!needsDevBaseRewrite) return;
|
|
256
|
+
const basePrefix = resolvedStartConfig.viteAppBase.replace(/\/$/, "");
|
|
257
|
+
server.middlewares.use((req, _res, next) => {
|
|
258
|
+
if (req.url && !req.url.startsWith(basePrefix)) req.url = basePrefix + req.url;
|
|
259
|
+
next();
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
devServerPlugin({
|
|
264
|
+
getConfig,
|
|
265
|
+
devSsrStylesEnabled: startPluginOpts?.dev?.ssrStyles?.enabled ?? true
|
|
266
|
+
}),
|
|
267
|
+
previewServerPlugin(),
|
|
268
|
+
{
|
|
269
|
+
name: "tanstack-start:core:capture-bundle",
|
|
270
|
+
applyToEnvironment(e) {
|
|
271
|
+
return e.name === VITE_ENVIRONMENT_NAMES.client || e.name === VITE_ENVIRONMENT_NAMES.server;
|
|
272
|
+
},
|
|
273
|
+
enforce: "post",
|
|
274
|
+
generateBundle(_options, bundle) {
|
|
275
|
+
const environment = this.environment.name;
|
|
276
|
+
if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) throw new Error(`Unknown environment: ${environment}`);
|
|
277
|
+
capturedBundle[environment] = bundle;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
];
|
|
361
281
|
}
|
|
362
282
|
function defineReplaceEnv(key, value) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
283
|
+
return {
|
|
284
|
+
[`process.env.${key}`]: JSON.stringify(value),
|
|
285
|
+
[`import.meta.env.${key}`]: JSON.stringify(value)
|
|
286
|
+
};
|
|
367
287
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
//# sourceMappingURL=plugin.js.map
|
|
288
|
+
//#endregion
|
|
289
|
+
export { TanStackStartVitePluginCore };
|
|
290
|
+
|
|
291
|
+
//# sourceMappingURL=plugin.js.map
|