vite-plugin-react-server 1.1.17 → 1.1.18
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/README.md +2 -2
- package/dist/package.json +5 -4
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
- package/dist/plugin/components/html.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +7 -12
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +2 -2
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
- package/dist/plugin/config/createModuleID.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +16 -2
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/extMap.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/mimeTypes.d.ts.map +1 -1
- package/dist/plugin/config/mimeTypes.js +67 -0
- package/dist/plugin/config/mimeTypes.js.map +1 -1
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -1
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +1 -1
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +39 -22
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/env/plugin.d.ts.map +1 -1
- package/dist/plugin/env/plugin.js +35 -2
- package/dist/plugin/env.js +37 -3
- package/dist/plugin/env.js.map +1 -1
- package/dist/plugin/error/toError.js +4 -4
- package/dist/plugin/error/toError.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.js +2 -2
- package/dist/plugin/helpers/cleanObject.js.map +1 -1
- package/dist/plugin/helpers/collectManifestCss.js +2 -2
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +3 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +12 -1
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createEventHandler.js +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +2 -2
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +1 -1
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/requestInfo.js +1 -1
- package/dist/plugin/helpers/requestInfo.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
- package/dist/plugin/helpers/sourceMap.d.ts.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +3 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +14 -8
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.js +1 -2
- package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.js +14 -18
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
- package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
- package/dist/plugin/react-server/configureReactServer.js +0 -12
- package/dist/plugin/react-server/configureReactServer.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +5 -14
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPages.js +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +24 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +18 -15
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/types.d.ts +4 -2
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
- package/dist/plugin/utils/envUrls.node.d.ts.map +1 -1
- package/dist/plugin/utils/urls.d.ts.map +1 -1
- package/dist/plugin/vendor/types.d.ts +2 -0
- package/dist/plugin/vendor/types.d.ts.map +1 -0
- package/dist/plugin/vendor/types.js +1 -0
- package/dist/plugin/worker/createWorker.js +1 -1
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +31 -17
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -6
- package/plugin/config/autoDiscover/resolveAutoDiscover.ts +6 -14
- package/plugin/config/mimeTypes.ts +75 -1
- package/plugin/config/resolveUserConfig.ts +46 -21
- package/plugin/env/plugin.ts +39 -3
- package/plugin/helpers/collectManifestCss.ts +2 -2
- package/plugin/helpers/collectViteModuleGraphCss.ts +3 -0
- package/plugin/helpers/createCssProps.tsx +20 -3
- package/plugin/helpers/requestInfo.ts +1 -1
- package/plugin/helpers/tryManifest.ts +20 -10
- package/plugin/loader/transformModuleIfNeeded.ts +1 -4
- package/plugin/react-client/configureWorkerRequestHandler.ts +16 -20
- package/plugin/react-server/configureReactServer.ts +0 -12
- package/plugin/react-static/configurePreviewServer.ts +1 -2
- package/plugin/react-static/plugin.ts +20 -27
- package/plugin/transformer/plugin.server.ts +22 -15
- package/plugin/types.ts +8 -6
- package/plugin/vendor/types.ts +0 -0
- package/plugin/worker/rsc/state.ts +53 -28
|
@@ -1,17 +1,91 @@
|
|
|
1
|
-
|
|
2
1
|
export const MIME_TYPES: Record<string, string> = {
|
|
2
|
+
// HTML and Web
|
|
3
3
|
'.html': 'text/html',
|
|
4
|
+
'.htm': 'text/html',
|
|
5
|
+
'.xhtml': 'application/xhtml+xml',
|
|
6
|
+
'.xml': 'application/xml',
|
|
4
7
|
'.css': 'text/css',
|
|
5
8
|
'.js': 'application/javascript',
|
|
9
|
+
'.mjs': 'application/javascript',
|
|
10
|
+
'.cjs': 'application/javascript',
|
|
11
|
+
'.jsx': 'application/javascript',
|
|
12
|
+
'.ts': 'application/javascript',
|
|
13
|
+
'.tsx': 'application/javascript',
|
|
6
14
|
'.json': 'application/json',
|
|
15
|
+
'.map': 'application/json',
|
|
16
|
+
'.wasm': 'application/wasm',
|
|
17
|
+
'.webmanifest': 'application/manifest+json',
|
|
18
|
+
|
|
19
|
+
// Images
|
|
7
20
|
'.png': 'image/png',
|
|
8
21
|
'.jpg': 'image/jpeg',
|
|
9
22
|
'.jpeg': 'image/jpeg',
|
|
10
23
|
'.gif': 'image/gif',
|
|
11
24
|
'.svg': 'image/svg+xml',
|
|
12
25
|
'.ico': 'image/x-icon',
|
|
26
|
+
'.webp': 'image/webp',
|
|
27
|
+
'.avif': 'image/avif',
|
|
28
|
+
'.bmp': 'image/bmp',
|
|
29
|
+
'.tiff': 'image/tiff',
|
|
30
|
+
'.tif': 'image/tiff',
|
|
31
|
+
'.heic': 'image/heic',
|
|
32
|
+
'.heif': 'image/heif',
|
|
33
|
+
'.apng': 'image/apng',
|
|
34
|
+
|
|
35
|
+
// Fonts
|
|
13
36
|
'.woff': 'font/woff',
|
|
14
37
|
'.woff2': 'font/woff2',
|
|
15
38
|
'.ttf': 'font/ttf',
|
|
39
|
+
'.otf': 'font/otf',
|
|
40
|
+
'.eot': 'application/vnd.ms-fontobject',
|
|
41
|
+
'.sfnt': 'font/sfnt',
|
|
42
|
+
|
|
43
|
+
// Video
|
|
44
|
+
'.mp4': 'video/mp4',
|
|
45
|
+
'.webm': 'video/webm',
|
|
46
|
+
'.m4v': 'video/x-m4v',
|
|
47
|
+
'.m4s': 'video/iso.segment',
|
|
48
|
+
'.m3u8': 'application/vnd.apple.mpegurl',
|
|
49
|
+
'.mpd': 'application/dash+xml',
|
|
50
|
+
'.mov': 'video/quicktime',
|
|
51
|
+
'.avi': 'video/x-msvideo',
|
|
52
|
+
'.wmv': 'video/x-ms-wmv',
|
|
53
|
+
'.flv': 'video/x-flv',
|
|
54
|
+
'.mkv': 'video/x-matroska',
|
|
55
|
+
'.3gp': 'video/3gpp',
|
|
56
|
+
'.m2ts': 'video/mp2t',
|
|
57
|
+
|
|
58
|
+
// Audio
|
|
59
|
+
'.mp3': 'audio/mpeg',
|
|
60
|
+
'.wav': 'audio/wav',
|
|
61
|
+
'.ogg': 'audio/ogg',
|
|
62
|
+
'.m4a': 'audio/mp4',
|
|
63
|
+
'.aac': 'audio/aac',
|
|
64
|
+
'.flac': 'audio/flac',
|
|
65
|
+
|
|
66
|
+
// Documents
|
|
67
|
+
'.pdf': 'application/pdf',
|
|
68
|
+
'.doc': 'application/msword',
|
|
69
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
70
|
+
'.xls': 'application/vnd.ms-excel',
|
|
71
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
72
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
73
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
74
|
+
|
|
75
|
+
// Archives
|
|
76
|
+
'.zip': 'application/zip',
|
|
77
|
+
'.rar': 'application/x-rar-compressed',
|
|
78
|
+
'.7z': 'application/x-7z-compressed',
|
|
79
|
+
'.tar': 'application/x-tar',
|
|
80
|
+
'.gz': 'application/gzip',
|
|
81
|
+
|
|
82
|
+
// Data
|
|
83
|
+
'.csv': 'text/csv',
|
|
84
|
+
'.txt': 'text/plain',
|
|
85
|
+
'.md': 'text/markdown',
|
|
86
|
+
'.yaml': 'application/yaml',
|
|
87
|
+
'.yml': 'application/yaml',
|
|
88
|
+
|
|
89
|
+
// React specific
|
|
16
90
|
'.rsc': 'text/x-component'
|
|
17
91
|
};
|
|
@@ -86,9 +86,7 @@ export function resolveUserConfig<
|
|
|
86
86
|
info.type === "asset" &&
|
|
87
87
|
userOptions.autoDiscover.cssPattern(value)
|
|
88
88
|
) {
|
|
89
|
-
const found = entry.css?.find((css) =>
|
|
90
|
-
css.startsWith(id as string)
|
|
91
|
-
);
|
|
89
|
+
const found = entry.css?.find((css) => css.startsWith(id as string));
|
|
92
90
|
if (found) {
|
|
93
91
|
return found;
|
|
94
92
|
} else {
|
|
@@ -154,7 +152,9 @@ export function resolveUserConfig<
|
|
|
154
152
|
}
|
|
155
153
|
stashedReturns[inputId] = r;
|
|
156
154
|
}
|
|
157
|
-
|
|
155
|
+
// in the case of empty basePath, it will not be sliced from the path, so, we need to slice it here
|
|
156
|
+
// at the last possible moment as to not confuse the rest of the logic around the basePath
|
|
157
|
+
return stashedReturns[inputId].slice(Number(stashedReturns[inputId].startsWith("/")));
|
|
158
158
|
}),
|
|
159
159
|
assetFileNames: process.env["VITEST"]
|
|
160
160
|
? undefined
|
|
@@ -171,7 +171,9 @@ export function resolveUserConfig<
|
|
|
171
171
|
}
|
|
172
172
|
stashedReturns[inputId] = r;
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
// in the case of empty basePath, it will not be sliced from the path, so, we need to slice it here
|
|
175
|
+
// at the last possible moment as to not confuse the rest of the logic around the basePath
|
|
176
|
+
return stashedReturns[inputId].slice(Number(stashedReturns[inputId].startsWith("/")));
|
|
175
177
|
}),
|
|
176
178
|
chunkFileNames:
|
|
177
179
|
userDefinedChunkFileNames ??
|
|
@@ -194,7 +196,9 @@ export function resolveUserConfig<
|
|
|
194
196
|
}
|
|
195
197
|
stashedReturns[inputId] = r;
|
|
196
198
|
}
|
|
197
|
-
|
|
199
|
+
// in the case of empty basePath, it will not be sliced from the path, so, we need to slice it here
|
|
200
|
+
// at the last possible moment as to not confuse the rest of the logic around the basePath
|
|
201
|
+
return stashedReturns[inputId].slice(Number(stashedReturns[inputId].startsWith("/")));
|
|
198
202
|
}),
|
|
199
203
|
format: "esm",
|
|
200
204
|
exports: "named",
|
|
@@ -207,7 +211,11 @@ export function resolveUserConfig<
|
|
|
207
211
|
? [config.build?.rollupOptions?.output, pluginOutput]
|
|
208
212
|
: pluginOutput;
|
|
209
213
|
const vitePrefix = config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX;
|
|
210
|
-
const mode =
|
|
214
|
+
const mode =
|
|
215
|
+
config.mode ??
|
|
216
|
+
process.env[`${vitePrefix}MODE`] ??
|
|
217
|
+
process.env["NODE_ENV"] ??
|
|
218
|
+
"production";
|
|
211
219
|
const minify = config.build?.minify;
|
|
212
220
|
|
|
213
221
|
const srrConfig = {
|
|
@@ -229,15 +237,20 @@ export function resolveUserConfig<
|
|
|
229
237
|
},
|
|
230
238
|
};
|
|
231
239
|
let publicOrigin =
|
|
232
|
-
userOptions.publicOrigin ?? process.env
|
|
240
|
+
userOptions.publicOrigin ?? process.env[`${vitePrefix}PUBLIC_ORIGIN`] ?? "";
|
|
233
241
|
let PROD = mode === "production";
|
|
234
242
|
let DEV = mode === "development";
|
|
243
|
+
let port =
|
|
244
|
+
typeof config.server?.port === "number" ? config.server?.port : 5173;
|
|
245
|
+
let strictPort = config.server?.strictPort ?? true;
|
|
246
|
+
let host =
|
|
247
|
+
typeof config.server?.host === "string" ? config.server?.host : "localhost";
|
|
235
248
|
if (configEnv.command === "serve" && !configEnv.isPreview) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
249
|
+
if (strictPort) {
|
|
250
|
+
publicOrigin = `http${config.server?.https ? "s" : ""}://${host}:${port}`;
|
|
251
|
+
} else {
|
|
252
|
+
publicOrigin = "";
|
|
253
|
+
}
|
|
241
254
|
}
|
|
242
255
|
const ssrDefine = ssr
|
|
243
256
|
? {
|
|
@@ -257,13 +270,13 @@ export function resolveUserConfig<
|
|
|
257
270
|
// these will never be cleaned up, because, we are resolving the user config
|
|
258
271
|
// and it's assumed the thread closes after this and we don't want
|
|
259
272
|
// it to change after the config has been resolved
|
|
260
|
-
if (process.env
|
|
261
|
-
process.env
|
|
273
|
+
if (process.env[`${vitePrefix}BASE_URL`] !== userOptions.moduleBaseURL) {
|
|
274
|
+
process.env[`${vitePrefix}BASE_URL`] = userOptions.moduleBaseURL;
|
|
262
275
|
}
|
|
263
|
-
if (process.env
|
|
264
|
-
process.env
|
|
276
|
+
if (process.env[`${vitePrefix}PUBLIC_ORIGIN`] !== publicOrigin) {
|
|
277
|
+
process.env[`${vitePrefix}PUBLIC_ORIGIN`] = publicOrigin;
|
|
265
278
|
}
|
|
266
|
-
|
|
279
|
+
|
|
267
280
|
if (condition === "react-client") {
|
|
268
281
|
// client plugin build options (client plugin still outputs server files)
|
|
269
282
|
const clientConfig = {
|
|
@@ -282,6 +295,15 @@ export function resolveUserConfig<
|
|
|
282
295
|
},
|
|
283
296
|
define: define,
|
|
284
297
|
ssr: srrConfig,
|
|
298
|
+
server: {
|
|
299
|
+
...config.server,
|
|
300
|
+
// common default for stricter server operations
|
|
301
|
+
// and ensures tests that use a server will fail early
|
|
302
|
+
// also, we can't set the public origin without a port
|
|
303
|
+
port: port,
|
|
304
|
+
strictPort: strictPort,
|
|
305
|
+
host: host,
|
|
306
|
+
},
|
|
285
307
|
// client build options
|
|
286
308
|
build: {
|
|
287
309
|
...config.build,
|
|
@@ -298,9 +320,12 @@ export function resolveUserConfig<
|
|
|
298
320
|
minify: minify,
|
|
299
321
|
rollupOptions: {
|
|
300
322
|
...config.build?.rollupOptions,
|
|
301
|
-
input:
|
|
302
|
-
|
|
303
|
-
|
|
323
|
+
input: Object.fromEntries(
|
|
324
|
+
Object.entries(autoDiscoveredFiles.inputs).map(([key, value]) => [
|
|
325
|
+
key,
|
|
326
|
+
value.slice(Number(value.startsWith("/"))),
|
|
327
|
+
])
|
|
328
|
+
),
|
|
304
329
|
output: newOutput,
|
|
305
330
|
preserveEntrySignatures:
|
|
306
331
|
config.build?.rollupOptions?.preserveEntrySignatures ??
|
package/plugin/env/plugin.ts
CHANGED
|
@@ -44,12 +44,20 @@ const cleanupInitialUserConfigEnv = resolveEnv(
|
|
|
44
44
|
*/
|
|
45
45
|
export function envPlugin(): Plugin {
|
|
46
46
|
let cleanupEnv: (() => void) | undefined;
|
|
47
|
+
let vitePrefix = DEFAULT_CONFIG.ENV_PREFIX as string;
|
|
47
48
|
return {
|
|
48
49
|
name: "vite-plugin-react-server:env",
|
|
49
50
|
enforce: "pre",
|
|
50
51
|
config(config, { mode }) {
|
|
52
|
+
if(config.envPrefix) {
|
|
53
|
+
if(typeof config.envPrefix === "string") {
|
|
54
|
+
vitePrefix = config.envPrefix;
|
|
55
|
+
} else if(Array.isArray(config.envPrefix)) {
|
|
56
|
+
vitePrefix = config.envPrefix[0];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
51
59
|
const invalidEnv =
|
|
52
|
-
(mode !== undefined && mode !== process.env
|
|
60
|
+
(mode !== undefined && mode !== process.env[`${vitePrefix}MODE`]) ||
|
|
53
61
|
(config.root !== undefined && config.root !== userProjectRoot);
|
|
54
62
|
if (invalidEnv) {
|
|
55
63
|
cleanupInitialUserConfigEnv();
|
|
@@ -57,9 +65,9 @@ export function envPlugin(): Plugin {
|
|
|
57
65
|
// Clean up any previous env setup
|
|
58
66
|
const cleanupUserConfigEnv = invalidEnv
|
|
59
67
|
? resolveEnv(
|
|
60
|
-
mode || process.env
|
|
68
|
+
mode || process.env[`${vitePrefix}MODE`] || "production",
|
|
61
69
|
config.root ?? userProjectRoot,
|
|
62
|
-
|
|
70
|
+
vitePrefix
|
|
63
71
|
)
|
|
64
72
|
: cleanupInitialUserConfigEnv;
|
|
65
73
|
const cleanupUserConfig = resolveConfigDefine(config);
|
|
@@ -74,5 +82,33 @@ export function envPlugin(): Plugin {
|
|
|
74
82
|
// Clean up environment variables when the bundle is closed
|
|
75
83
|
cleanupEnv?.();
|
|
76
84
|
},
|
|
85
|
+
configureServer(server) {
|
|
86
|
+
let envPrefix = Array.isArray(server.config.envPrefix) ? server.config.envPrefix[0] : server.config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX;
|
|
87
|
+
let publicOrigin = process.env[`${envPrefix}PUBLIC_ORIGIN`] ?? ""
|
|
88
|
+
|
|
89
|
+
let desiredPort = server.config.server.port;
|
|
90
|
+
let shouldUpdatePublicOrigin = false;
|
|
91
|
+
if (publicOrigin && publicOrigin.includes(`:${desiredPort}`)) {
|
|
92
|
+
shouldUpdatePublicOrigin = true;
|
|
93
|
+
}
|
|
94
|
+
// Listen for when the server actually starts
|
|
95
|
+
if (shouldUpdatePublicOrigin) {
|
|
96
|
+
server.httpServer?.once("listening", () => {
|
|
97
|
+
const address = server.httpServer?.address();
|
|
98
|
+
if (address && typeof address !== "string") {
|
|
99
|
+
const port = address.port;
|
|
100
|
+
if (port !== desiredPort) {
|
|
101
|
+
let envPrefix = Array.isArray(server.config.envPrefix) ? server.config.envPrefix[0] : server.config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX;
|
|
102
|
+
const newOrigin = publicOrigin.replace(
|
|
103
|
+
`:${desiredPort}`,
|
|
104
|
+
`:${port}`
|
|
105
|
+
);
|
|
106
|
+
process.env[`${envPrefix}PUBLIC_ORIGIN`] = newOrigin
|
|
107
|
+
console.warn("PUBLIC_ORIGIN did not match the port: " + port);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
77
113
|
};
|
|
78
114
|
}
|
|
@@ -27,7 +27,7 @@ export function collectManifestCss(
|
|
|
27
27
|
// Add CSS files from the css property
|
|
28
28
|
if (fileInfo.css) {
|
|
29
29
|
for (const cssFile of fileInfo.css) {
|
|
30
|
-
cssInputs[cssFile] = cssFile
|
|
30
|
+
cssInputs[cssFile] = cssFile;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -46,7 +46,7 @@ export function collectManifestCss(
|
|
|
46
46
|
const importedFile = manifest[importPath];
|
|
47
47
|
if (importedFile?.css) {
|
|
48
48
|
for (const cssFile of importedFile.css) {
|
|
49
|
-
cssInputs[cssFile] = cssFile
|
|
49
|
+
cssInputs[cssFile] = cssFile;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -51,6 +51,7 @@ export async function collectViteModuleGraphCss<
|
|
|
51
51
|
| "loader"
|
|
52
52
|
| "normalizer"
|
|
53
53
|
| "moduleID"
|
|
54
|
+
| "publicOrigin"
|
|
54
55
|
>;
|
|
55
56
|
}): Promise<CollectViteModuleGraphCssResult> {
|
|
56
57
|
const {
|
|
@@ -59,6 +60,7 @@ export async function collectViteModuleGraphCss<
|
|
|
59
60
|
moduleBasePath,
|
|
60
61
|
moduleRootPath,
|
|
61
62
|
projectRoot,
|
|
63
|
+
publicOrigin,
|
|
62
64
|
css,
|
|
63
65
|
loader,
|
|
64
66
|
normalizer,
|
|
@@ -113,6 +115,7 @@ export async function collectViteModuleGraphCss<
|
|
|
113
115
|
css: css,
|
|
114
116
|
normalizer: normalizer,
|
|
115
117
|
moduleID: moduleID,
|
|
118
|
+
publicOrigin: publicOrigin,
|
|
116
119
|
},
|
|
117
120
|
});
|
|
118
121
|
cssFiles.set(mod?.url, cssContent);
|
|
@@ -41,6 +41,7 @@ export const createCssProps = <
|
|
|
41
41
|
| "projectRoot"
|
|
42
42
|
| "normalizer"
|
|
43
43
|
| "moduleID"
|
|
44
|
+
| "publicOrigin"
|
|
44
45
|
>;
|
|
45
46
|
}): CssContent<InlineCSS> => {
|
|
46
47
|
const { css, moduleRootPath } = userOptions;
|
|
@@ -77,15 +78,31 @@ export const createCssProps = <
|
|
|
77
78
|
: {}),
|
|
78
79
|
} as CssContent<InlineCSS>;
|
|
79
80
|
}
|
|
81
|
+
const processEnv = process.env || {};
|
|
82
|
+
const hasEnv= typeof processEnv.VITE_PUBLIC_ORIGIN === "string" &&
|
|
83
|
+
processEnv.VITE_PUBLIC_ORIGIN !== "";
|
|
84
|
+
const importMeta = import.meta || {};
|
|
85
|
+
const hasMetaEnv = 'env' in importMeta && typeof importMeta.env.PUBLIC_ORIGIN === "string" &&
|
|
86
|
+
importMeta.env.PUBLIC_ORIGIN !== "";
|
|
87
|
+
// final public origin check
|
|
88
|
+
if((hasEnv || hasMetaEnv) && userOptions.publicOrigin) {
|
|
89
|
+
// change the public origin to the one from the env
|
|
90
|
+
if(hasEnv && userOptions.publicOrigin !== processEnv.VITE_PUBLIC_ORIGIN) {
|
|
91
|
+
// prefer potentially dynamic process.env
|
|
92
|
+
userOptions.publicOrigin = processEnv.VITE_PUBLIC_ORIGIN;
|
|
93
|
+
} else if(hasMetaEnv && userOptions.publicOrigin !== import.meta.env.PUBLIC_ORIGIN) {
|
|
94
|
+
// static import.meta.env
|
|
95
|
+
userOptions.publicOrigin = import.meta.env.PUBLIC_ORIGIN;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
80
98
|
// Default case
|
|
81
99
|
return {
|
|
82
100
|
id: moduleID,
|
|
83
101
|
as: "link",
|
|
84
102
|
rel: "stylesheet",
|
|
85
103
|
href:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
? new URL(moduleID, process.env.VITE_PUBLIC_ORIGIN).href
|
|
104
|
+
userOptions.publicOrigin !== ""
|
|
105
|
+
? new URL(moduleID, userOptions.publicOrigin).href
|
|
89
106
|
: moduleID,
|
|
90
107
|
precedence: "high",
|
|
91
108
|
} as CssContent<InlineCSS>;
|
|
@@ -8,7 +8,7 @@ type TryManifestOptions<SSR extends boolean = false> = {
|
|
|
8
8
|
outDir: string;
|
|
9
9
|
ssrManifest?: SSR;
|
|
10
10
|
preserveModulesRoot?: string;
|
|
11
|
-
manifestPath?: string | undefined;
|
|
11
|
+
manifestPath?: string | boolean | undefined;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export async function tryManifest<SSR extends boolean>(
|
|
@@ -23,16 +23,26 @@ export async function tryManifest<SSR extends boolean>(
|
|
|
23
23
|
type: "error";
|
|
24
24
|
error: Error;
|
|
25
25
|
manifest?: never;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
type: "skip";
|
|
29
|
+
}
|
|
30
|
+
> {
|
|
31
|
+
let path = options.manifestPath;
|
|
32
|
+
if (path === false) {
|
|
33
|
+
return {
|
|
34
|
+
type: "skip",
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (options.ssrManifest) {
|
|
38
|
+
path = join(".vite", "ssr-manifest.json");
|
|
39
|
+
} else {
|
|
40
|
+
path = join(".vite", "manifest.json");
|
|
41
|
+
}
|
|
34
42
|
try {
|
|
35
|
-
const result = JSON.parse(
|
|
43
|
+
const result = JSON.parse(
|
|
44
|
+
await readFile(resolve(options.root, options.outDir, path), "utf-8")
|
|
45
|
+
);
|
|
36
46
|
return {
|
|
37
47
|
type: "success",
|
|
38
48
|
manifest: result,
|
|
@@ -10,9 +10,6 @@ export function transformModuleIfNeeded(
|
|
|
10
10
|
isClientComponent: boolean | RegExpMatchArray | null = DEFAULT_CONFIG.AUTO_DISCOVER.isClientComponentCode(source),
|
|
11
11
|
isServerEnvironment = getCondition() === "react-server"
|
|
12
12
|
) {
|
|
13
|
-
// Parse source and handle source maps
|
|
14
|
-
const ast = parse(source);
|
|
15
|
-
|
|
16
13
|
// Handle environment-specific cases
|
|
17
14
|
if (
|
|
18
15
|
(isServerEnvironment && !isServerFunction && !isClientComponent) ||
|
|
@@ -24,7 +21,7 @@ export function transformModuleIfNeeded(
|
|
|
24
21
|
const result = transformModuleWithPreservedFunctions(
|
|
25
22
|
source,
|
|
26
23
|
moduleId,
|
|
27
|
-
|
|
24
|
+
parse(source),
|
|
28
25
|
isServerFunction,
|
|
29
26
|
isClientComponent
|
|
30
27
|
);
|
|
@@ -19,6 +19,7 @@ import type { RscWorkerInputMessage } from "../worker/types.js";
|
|
|
19
19
|
import { Readable } from "node:stream";
|
|
20
20
|
import type { ReadableStream } from "node:stream/web";
|
|
21
21
|
import { PassThrough } from "node:stream";
|
|
22
|
+
import { logError, toError } from "../error/toError.js";
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Configures the worker request handler.
|
|
@@ -102,7 +103,7 @@ export async function configureWorkerRequestHandler<
|
|
|
102
103
|
}
|
|
103
104
|
const body = Buffer.concat(chunks).toString();
|
|
104
105
|
const parsed = JSON.parse(body);
|
|
105
|
-
|
|
106
|
+
|
|
106
107
|
// Get action ID and args from the request body
|
|
107
108
|
let id: string;
|
|
108
109
|
let args: unknown[];
|
|
@@ -153,9 +154,7 @@ export async function configureWorkerRequestHandler<
|
|
|
153
154
|
} else if (message.type === "ERROR") {
|
|
154
155
|
passThrough.end();
|
|
155
156
|
currentWorker!.removeListener("message", messageHandler);
|
|
156
|
-
|
|
157
|
-
error: message.error,
|
|
158
|
-
});
|
|
157
|
+
logError(message.error, server.config.logger);
|
|
159
158
|
}
|
|
160
159
|
};
|
|
161
160
|
|
|
@@ -163,27 +162,24 @@ export async function configureWorkerRequestHandler<
|
|
|
163
162
|
|
|
164
163
|
// Handle errors
|
|
165
164
|
passThrough.on("error", (error) => {
|
|
166
|
-
server.config.logger
|
|
167
|
-
error,
|
|
168
|
-
});
|
|
165
|
+
logError(error, server.config.logger);
|
|
169
166
|
res.end();
|
|
170
167
|
});
|
|
171
168
|
|
|
172
169
|
return;
|
|
173
170
|
} catch (error) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
error,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
171
|
+
const err = toError(error);
|
|
172
|
+
logError(err, server.config.logger);
|
|
179
173
|
res.statusCode = 500;
|
|
180
|
-
res.end(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
174
|
+
res.end(
|
|
175
|
+
JSON.stringify({
|
|
176
|
+
type: "server-action-response",
|
|
177
|
+
returnValue: {
|
|
178
|
+
success: false,
|
|
179
|
+
error: err.message,
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
);
|
|
187
183
|
return;
|
|
188
184
|
}
|
|
189
185
|
}
|
|
@@ -320,5 +316,5 @@ export async function configureWorkerRequestHandler<
|
|
|
320
316
|
};
|
|
321
317
|
// attach handler to the server
|
|
322
318
|
server.middlewares.use(handler);
|
|
323
|
-
//
|
|
319
|
+
// port check, should be handled by strictPort
|
|
324
320
|
}
|
|
@@ -170,16 +170,4 @@ export async function configureReactServer<
|
|
|
170
170
|
}
|
|
171
171
|
});
|
|
172
172
|
// Listen for when the server actually starts
|
|
173
|
-
server.httpServer?.once("listening", () => {
|
|
174
|
-
const address = server.httpServer?.address();
|
|
175
|
-
if (address && typeof address !== "string") {
|
|
176
|
-
const port = address.port;
|
|
177
|
-
const host = server.config.server.host ?? "localhost";
|
|
178
|
-
const protocol = server.config.server.https ? "https" : "http";
|
|
179
|
-
handlerOptions.publicOrigin = `${protocol}://${host}:${port}`;
|
|
180
|
-
if (handlerOptions.publicOrigin !== process.env.VITE_PUBLIC_ORIGIN) {
|
|
181
|
-
process.env.VITE_PUBLIC_ORIGIN = handlerOptions.publicOrigin;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
173
|
}
|
|
@@ -39,9 +39,8 @@ export async function configurePreviewServer<
|
|
|
39
39
|
staticHostDir,
|
|
40
40
|
server.config.logger
|
|
41
41
|
);
|
|
42
|
-
|
|
43
42
|
// Handle static files including CSS
|
|
44
|
-
if (filePath) {
|
|
43
|
+
if (filePath && contentType.includes("text/x-component")) {
|
|
45
44
|
try {
|
|
46
45
|
const stats = await stat(filePath);
|
|
47
46
|
if (stats.isFile()) {
|
|
@@ -49,7 +49,6 @@ import {
|
|
|
49
49
|
} from "../helpers/serializeUserOptions.js";
|
|
50
50
|
import { collectManifestCss } from "../helpers/collectManifestCss.js";
|
|
51
51
|
import { createCssProps } from "../helpers/createCssProps.js";
|
|
52
|
-
import { tryManifest } from "../helpers/tryManifest.js";
|
|
53
52
|
import { performance } from "node:perf_hooks";
|
|
54
53
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
55
54
|
import { baseURL } from "../utils/envUrls.node.js";
|
|
@@ -101,7 +100,7 @@ export function reactStaticPlugin<
|
|
|
101
100
|
if (config.root && config.root !== userOptions.projectRoot) {
|
|
102
101
|
userOptions.projectRoot = config.root;
|
|
103
102
|
}
|
|
104
|
-
if(configEnv.command !== "build") {
|
|
103
|
+
if (configEnv.command !== "build") {
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
// Initialize autoDiscoveredFiles for both server and client builds
|
|
@@ -165,35 +164,29 @@ export function reactStaticPlugin<
|
|
|
165
164
|
bundle,
|
|
166
165
|
normalizer: userOptions.normalizer,
|
|
167
166
|
});
|
|
168
|
-
|
|
167
|
+
const manifestPath =
|
|
168
|
+
typeof resolvedConfig.build.manifest === "string"
|
|
169
|
+
? resolvedConfig.build.manifest
|
|
170
|
+
: ".vite/manifest.json";
|
|
171
|
+
if (!("source" in bundleManifest[manifestPath])) {
|
|
169
172
|
throw new Error("Server manifest not found");
|
|
170
173
|
}
|
|
171
174
|
|
|
172
175
|
serverManifest = JSON.parse(
|
|
173
|
-
bundleManifest[
|
|
176
|
+
bundleManifest[manifestPath].source as string
|
|
174
177
|
);
|
|
175
178
|
|
|
176
179
|
if (!serverManifest) {
|
|
177
180
|
throw new Error("Failed to parse server manifest");
|
|
178
181
|
}
|
|
179
|
-
|
|
180
|
-
const clientManifestResult = await tryManifest({
|
|
181
|
-
root: userOptions.projectRoot,
|
|
182
|
-
outDir: join(userOptions.build.outDir, userOptions.build.client),
|
|
183
|
-
ssrManifest: false,
|
|
184
|
-
});
|
|
185
|
-
if (clientManifestResult.type === "error") {
|
|
186
|
-
throw clientManifestResult.error;
|
|
187
|
-
}
|
|
188
|
-
const clientManifest = clientManifestResult.manifest;
|
|
189
182
|
|
|
190
|
-
buildLoader = await createBuildLoader
|
|
183
|
+
buildLoader = await createBuildLoader(
|
|
191
184
|
{
|
|
192
185
|
userConfig,
|
|
193
|
-
userOptions: userOptions
|
|
186
|
+
userOptions: userOptions,
|
|
194
187
|
serverManifest: serverManifest ?? {},
|
|
195
188
|
staticManifest: autoDiscoveredFiles?.staticManifest ?? {},
|
|
196
|
-
clientManifest:
|
|
189
|
+
clientManifest: {},
|
|
197
190
|
},
|
|
198
191
|
bundle
|
|
199
192
|
);
|
|
@@ -230,7 +223,6 @@ export function reactStaticPlugin<
|
|
|
230
223
|
transformedServerManifest,
|
|
231
224
|
props ? [page, props] : page
|
|
232
225
|
);
|
|
233
|
-
|
|
234
226
|
// Create a map for this page's CSS files
|
|
235
227
|
const pageCssMap: Map<string, CssContent> = new Map();
|
|
236
228
|
// Add global styles if they exist
|
|
@@ -240,15 +232,16 @@ export function reactStaticPlugin<
|
|
|
240
232
|
String(r.default)
|
|
241
233
|
);
|
|
242
234
|
if (cssContent === "undefined" || !cssContent) {
|
|
243
|
-
cssContent =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
235
|
+
cssContent =
|
|
236
|
+
(await readFile(
|
|
237
|
+
join(
|
|
238
|
+
userOptions.projectRoot,
|
|
239
|
+
userOptions.build.outDir,
|
|
240
|
+
userOptions.build.static,
|
|
241
|
+
key
|
|
242
|
+
),
|
|
243
|
+
"utf-8"
|
|
244
|
+
)) ?? "";
|
|
252
245
|
}
|
|
253
246
|
if (cssContent) {
|
|
254
247
|
globalCss.set(
|