vite-plugin-react-server 0.3.18 → 0.3.19
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 +119 -118
- package/bin/patch.mjs +8 -2
- package/dist/package.json +3 -3
- package/dist/plugin/checkFilesExist.d.ts.map +1 -1
- package/dist/plugin/checkFilesExist.js +6 -2
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +23 -0
- package/dist/plugin/collect-manifest-client-files.d.ts.map +1 -0
- package/dist/plugin/collect-manifest-client-files.js +117 -0
- package/dist/plugin/collect-manifest-client-files.js.map +1 -0
- package/dist/plugin/components.d.ts +9 -9
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +50 -9
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +7 -6
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +8 -5
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js +2 -7
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/mimeTypes.d.ts +2 -0
- package/dist/plugin/config/mimeTypes.d.ts.map +1 -0
- package/dist/plugin/config/mimeTypes.js +24 -0
- package/dist/plugin/config/mimeTypes.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +41 -28
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +1 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +9 -5
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +10 -5
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy-dir.js +23 -18
- package/dist/plugin/copy-dir.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +22 -0
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -0
- package/dist/plugin/{react-server → helpers}/createHandler.js +36 -48
- package/dist/plugin/helpers/createHandler.js.map +1 -0
- package/dist/plugin/{react-server → helpers}/createRscStream.d.ts +2 -1
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -0
- package/dist/plugin/helpers/createRscStream.js +71 -0
- package/dist/plugin/helpers/createRscStream.js.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +12 -4
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +8 -5
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.js.map +1 -1
- package/dist/plugin/loader/react-loader.js +2 -2
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +49 -14
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +18 -76
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +2 -0
- package/dist/plugin/react-server/index.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts +2 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +53 -217
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/index.d.ts +2 -0
- package/dist/plugin/react-static/index.d.ts.map +1 -0
- package/dist/plugin/react-static/index.js +1 -0
- package/dist/plugin/react-static/plugin.d.ts +7 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -0
- package/dist/plugin/react-static/plugin.js +199 -0
- package/dist/plugin/react-static/plugin.js.map +1 -0
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +9 -0
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/root.d.ts +2 -0
- package/dist/plugin/root.d.ts.map +1 -0
- package/dist/plugin/root.js +12 -0
- package/dist/plugin/root.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +32 -23
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/types.d.ts +1 -18
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +24 -6
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +0 -1
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.d.ts +30 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +30 -2
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +3 -5
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +8 -2
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/html/plugin.js +2 -3
- package/dist/plugin/worker/html/renderPages.d.ts +8 -4
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +118 -83
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +89 -84
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/plugin.js +1 -2
- package/dist/plugin/worker/rsc/rsc-worker.development.js +13 -18
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +4 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/plugin/checkFilesExist.ts +7 -3
- package/plugin/collect-manifest-client-files.ts +152 -0
- package/plugin/components.tsx +55 -10
- package/plugin/config/defaults.tsx +69 -0
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/mimeTypes.ts +17 -0
- package/plugin/config/resolveOptions.ts +48 -40
- package/plugin/config/resolvePages.ts +8 -4
- package/plugin/config/resolveUserConfig.ts +12 -9
- package/plugin/{react-server → helpers}/createHandler.ts +46 -63
- package/plugin/helpers/createRscStream.ts +81 -0
- package/plugin/helpers/getBundleManifest.ts +14 -5
- package/plugin/loader/createBuildLoader.ts +9 -6
- package/plugin/loader/css-loader.ts +0 -2
- package/plugin/loader/react-loader.ts +2 -2
- package/plugin/preserver/plugin.ts +64 -17
- package/plugin/react-client/plugin.ts +20 -91
- package/plugin/react-server/index.ts +2 -0
- package/plugin/react-server/plugin.ts +66 -293
- package/plugin/react-static/index.ts +1 -0
- package/plugin/react-static/plugin.ts +247 -0
- package/plugin/resolvePage.ts +9 -0
- package/plugin/root.ts +4 -0
- package/plugin/transformer/plugin.ts +40 -31
- package/plugin/transformer/types.ts +0 -19
- package/plugin/types.ts +25 -6
- package/plugin/worker/createWorker.ts +1 -1
- package/plugin/worker/html/README.md +63 -0
- package/plugin/worker/html/html-worker.development.tsx +89 -2
- package/plugin/worker/html/html-worker.production.tsx +8 -10
- package/plugin/worker/html/messageHandler.ts +8 -2
- package/plugin/worker/html/plugin.ts +2 -3
- package/plugin/worker/html/renderPages.ts +150 -114
- package/plugin/worker/rsc/README.md +58 -0
- package/plugin/worker/rsc/messageHandler.tsx +95 -111
- package/plugin/worker/rsc/plugin.ts +1 -2
- package/plugin/worker/rsc/rsc-worker.development.ts +12 -22
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -1
- package/plugin/worker/rsc/state.ts +0 -3
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +114 -12
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +10571 -121
- package/tsconfig.json +2 -2
- package/dist/plugin/collect-css-manifest.d.ts +0 -4
- package/dist/plugin/collect-css-manifest.d.ts.map +0 -1
- package/dist/plugin/collect-css-manifest.js +0 -65
- package/dist/plugin/collect-css-manifest.js.map +0 -1
- package/dist/plugin/config/createModuleIdGenerator.d.ts +0 -11
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +0 -1
- package/dist/plugin/config/createModuleIdGenerator.js +0 -44
- package/dist/plugin/config/createModuleIdGenerator.js.map +0 -1
- package/dist/plugin/loader/createCssLoader.d.ts +0 -30
- package/dist/plugin/loader/createCssLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createCssLoader.js +0 -35
- package/dist/plugin/loader/createPageLoader.d.ts +0 -24
- package/dist/plugin/loader/createPageLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createPageLoader.js +0 -50
- package/dist/plugin/loader/rsc/messageHandler.d.ts +0 -2
- package/dist/plugin/loader/rsc/messageHandler.d.ts.map +0 -1
- package/dist/plugin/loader/rsc/messageHandler.js +0 -1
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +0 -2
- package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +0 -1
- package/dist/plugin/loader/rsc/rsc-worker.development.js +0 -1
- package/dist/plugin/react-server/createHandler.d.ts +0 -17
- package/dist/plugin/react-server/createHandler.d.ts.map +0 -1
- package/dist/plugin/react-server/createHandler.js.map +0 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +0 -1
- package/dist/plugin/react-server/createRscStream.js +0 -70
- package/dist/plugin/react-server/createRscStream.js.map +0 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +0 -4
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +0 -1
- package/dist/plugin/react-server/createSsrHandler.js +0 -95
- package/dist/plugin/utils/logger.d.ts +0 -9
- package/dist/plugin/utils/logger.d.ts.map +0 -1
- package/dist/plugin/utils/logger.js +0 -68
- package/dist/plugin/utils/logger.js.map +0 -1
- package/plugin/collect-css-manifest.ts +0 -82
- package/plugin/config/createModuleIdGenerator.ts +0 -52
- package/plugin/config/defaults.ts +0 -51
- package/plugin/loader/createCssLoader.ts +0 -73
- package/plugin/loader/createPageLoader.ts +0 -103
- package/plugin/loader/rsc/messageHandler.tsx +0 -1
- package/plugin/loader/rsc/rsc-worker.development.ts +0 -1
- package/plugin/react-server/createRscStream.ts +0 -86
- package/plugin/react-server/createSsrHandler.ts +0 -125
- package/plugin/utils/logger.ts +0 -52
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vite-plugin-react-server
|
|
3
|
-
* Copyright (c) Nico Brinkkemper
|
|
4
|
-
* MIT License
|
|
5
|
-
*/
|
|
6
|
-
import { createLogger as createLogger$1 } from 'vite';
|
|
7
|
-
|
|
8
|
-
const isPrimitive = (value) => {
|
|
9
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "symbol";
|
|
10
|
-
};
|
|
11
|
-
const buildMessage = (prefix, msg, ...args) => {
|
|
12
|
-
let buildMsg = `[${prefix}] ${msg}`;
|
|
13
|
-
for (const arg of args) {
|
|
14
|
-
if (isPrimitive(arg)) {
|
|
15
|
-
buildMsg += `
|
|
16
|
-
[${prefix}] ${String(arg)}`;
|
|
17
|
-
} else if (arg instanceof Error) {
|
|
18
|
-
buildMsg += `
|
|
19
|
-
[${prefix}] ${arg.name}`;
|
|
20
|
-
buildMsg += `
|
|
21
|
-
[${prefix}] ${arg.message}`;
|
|
22
|
-
buildMsg += `
|
|
23
|
-
[${prefix}] ${arg.stack}`;
|
|
24
|
-
buildMsg += `
|
|
25
|
-
[${prefix}] ${arg.cause}`;
|
|
26
|
-
} else {
|
|
27
|
-
buildMsg += `
|
|
28
|
-
[${prefix}] ${JSON.stringify(arg)}`;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return buildMsg;
|
|
32
|
-
};
|
|
33
|
-
const createLogger = process.env["NODE_ENV"] === "development" ? (prefix, logLevel = "info") => {
|
|
34
|
-
const logger = createLogger$1(logLevel, {
|
|
35
|
-
allowClearScreen: true
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
clear: () => logger.clearScreen("info"),
|
|
39
|
-
info: (msg, ...args) => {
|
|
40
|
-
console.log(buildMessage(prefix, msg, ...args));
|
|
41
|
-
},
|
|
42
|
-
warn: (msg, ...args) => {
|
|
43
|
-
console.warn(buildMessage(prefix, msg, ...args));
|
|
44
|
-
},
|
|
45
|
-
error: (msg, ...args) => {
|
|
46
|
-
console.error(buildMessage(prefix, msg, ...args));
|
|
47
|
-
},
|
|
48
|
-
debug: (msg, ...args) => {
|
|
49
|
-
console.debug(buildMessage(prefix, msg, ...args));
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
} : () => {
|
|
53
|
-
return {
|
|
54
|
-
clear: () => {
|
|
55
|
-
},
|
|
56
|
-
info: () => {
|
|
57
|
-
},
|
|
58
|
-
warn: () => {
|
|
59
|
-
},
|
|
60
|
-
error: () => {
|
|
61
|
-
},
|
|
62
|
-
debug: () => {
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { createLogger };
|
|
68
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sources":["../../../plugin/utils/logger.ts"],"sourcesContent":["import { createLogger as createViteLogger, type LogLevel } from 'vite';\n\n\nconst isPrimitive = (value: any) => {\n return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'symbol';\n}\n\nconst buildMessage = (prefix: string, msg: string, ...args: any[]) => {\n let buildMsg = `[${prefix}] ${msg}`\n for(const arg of args) {\n if(isPrimitive(arg)) {\n buildMsg += `\\n[${prefix}] ${String(arg)}`;\n } else if(arg instanceof Error) {\n buildMsg += `\\n[${prefix}] ${arg.name}`\n buildMsg += `\\n[${prefix}] ${arg.message}`\n buildMsg += `\\n[${prefix}] ${arg.stack}`\n buildMsg += `\\n[${prefix}] ${arg.cause}`\n } else {\n buildMsg += `\\n[${prefix}] ${JSON.stringify(arg)}`;\n }\n }\n return buildMsg;\n}\n\nexport const createLogger = (process.env['NODE_ENV'] === 'development') ? (prefix: string, logLevel: LogLevel = 'info') => {\n const logger = createViteLogger(logLevel, {\n allowClearScreen: true\n });\n return {\n clear: () => logger.clearScreen('info'),\n info: (msg: string, ...args: any[]) => {\n console.log(buildMessage(prefix, msg, ...args))\n },\n warn: (msg: string, ...args: any[]) => {\n console.warn(buildMessage(prefix, msg, ...args))\n },\n error: (msg: string, ...args: any[]) => {\n console.error(buildMessage(prefix, msg, ...args))\n },\n debug: (msg: string, ...args: any[]) => {\n console.debug(buildMessage(prefix, msg, ...args))\n }\n };\n} : () => {\n return {\n clear: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n debug: () => {},\n };\n};"],"names":["createViteLogger"],"mappings":";;;;;;;AAGA,MAAM,WAAA,GAAc,CAAC,KAAe,KAAA;AAClC,EAAO,OAAA,OAAO,KAAU,KAAA,QAAA,IAAY,OAAO,KAAA,KAAU,YAAY,OAAO,KAAA,KAAU,SAAa,IAAA,OAAO,KAAU,KAAA,QAAA;AAClH,CAAA;AAEA,MAAM,YAAe,GAAA,CAAC,MAAgB,EAAA,GAAA,EAAA,GAAgB,IAAgB,KAAA;AACpE,EAAA,IAAI,QAAW,GAAA,CAAA,CAAA,EAAI,MAAM,CAAA,EAAA,EAAK,GAAG,CAAA,CAAA;AACjC,EAAA,KAAA,MAAU,OAAO,IAAM,EAAA;AACrB,IAAG,IAAA,WAAA,CAAY,GAAG,CAAG,EAAA;AACnB,MAAY,QAAA,IAAA;AAAA,CAAA,EAAM,MAAM,CAAA,EAAA,EAAK,MAAO,CAAA,GAAG,CAAC,CAAA,CAAA;AAAA,KAC1C,MAAA,IAAU,eAAe,KAAO,EAAA;AAC9B,MAAY,QAAA,IAAA;AAAA,CAAM,EAAA,MAAM,CAAK,EAAA,EAAA,GAAA,CAAI,IAAI,CAAA,CAAA;AACrC,MAAY,QAAA,IAAA;AAAA,CAAM,EAAA,MAAM,CAAK,EAAA,EAAA,GAAA,CAAI,OAAO,CAAA,CAAA;AACxC,MAAY,QAAA,IAAA;AAAA,CAAM,EAAA,MAAM,CAAK,EAAA,EAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AACtC,MAAY,QAAA,IAAA;AAAA,CAAM,EAAA,MAAM,CAAK,EAAA,EAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AAAA,KACjC,MAAA;AACL,MAAY,QAAA,IAAA;AAAA,CAAA,EAAM,MAAM,CAAA,EAAA,EAAK,IAAK,CAAA,SAAA,CAAU,GAAG,CAAC,CAAA,CAAA;AAAA;AAClD;AAEF,EAAO,OAAA,QAAA;AACT,CAAA;AAEa,MAAA,YAAA,GAAgB,QAAQ,GAAI,CAAA,UAAU,MAAM,aAAiB,GAAA,CAAC,MAAgB,EAAA,QAAA,GAAqB,MAAW,KAAA;AACzH,EAAM,MAAA,MAAA,GAASA,eAAiB,QAAU,EAAA;AAAA,IACxC,gBAAkB,EAAA;AAAA,GACnB,CAAA;AACD,EAAO,OAAA;AAAA,IACL,KAAO,EAAA,MAAM,MAAO,CAAA,WAAA,CAAY,MAAM,CAAA;AAAA,IACtC,IAAA,EAAM,CAAC,GAAA,EAAA,GAAgB,IAAgB,KAAA;AACrC,MAAA,OAAA,CAAQ,IAAI,YAAa,CAAA,MAAA,EAAQ,GAAK,EAAA,GAAG,IAAI,CAAC,CAAA;AAAA,KAChD;AAAA,IACA,IAAA,EAAM,CAAC,GAAA,EAAA,GAAgB,IAAgB,KAAA;AACrC,MAAA,OAAA,CAAQ,KAAK,YAAa,CAAA,MAAA,EAAQ,GAAK,EAAA,GAAG,IAAI,CAAC,CAAA;AAAA,KACjD;AAAA,IACA,KAAA,EAAO,CAAC,GAAA,EAAA,GAAgB,IAAgB,KAAA;AACtC,MAAA,OAAA,CAAQ,MAAM,YAAa,CAAA,MAAA,EAAQ,GAAK,EAAA,GAAG,IAAI,CAAC,CAAA;AAAA,KAClD;AAAA,IACA,KAAA,EAAO,CAAC,GAAA,EAAA,GAAgB,IAAgB,KAAA;AACtC,MAAA,OAAA,CAAQ,MAAM,YAAa,CAAA,MAAA,EAAQ,GAAK,EAAA,GAAG,IAAI,CAAC,CAAA;AAAA;AAClD,GACF;AACF,CAAA,GAAI,MAAM;AACR,EAAO,OAAA;AAAA,IACL,OAAO,MAAM;AAAA,KAAC;AAAA,IACd,MAAM,MAAM;AAAA,KAAC;AAAA,IACb,MAAM,MAAM;AAAA,KAAC;AAAA,IACb,OAAO,MAAM;AAAA,KAAC;AAAA,IACd,OAAO,MAAM;AAAA;AAAC,GAChB;AACF;;;;"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { Manifest, ModuleGraph } from 'vite';
|
|
2
|
-
|
|
3
|
-
export async function collectModuleGraphCss(
|
|
4
|
-
moduleGraph: ModuleGraph,
|
|
5
|
-
pagePath: string,
|
|
6
|
-
onCss?: (path: string) => void
|
|
7
|
-
) {
|
|
8
|
-
if (!pagePath) return new Map<string, string>();
|
|
9
|
-
|
|
10
|
-
const cssFiles = new Map<string, string>();
|
|
11
|
-
const pageModule = await moduleGraph.getModuleByUrl(pagePath, true);
|
|
12
|
-
if (!pageModule) {
|
|
13
|
-
return new Map<string, string>();
|
|
14
|
-
}
|
|
15
|
-
const seen = new Set<string>();
|
|
16
|
-
const walkModule = (mod: any) => {
|
|
17
|
-
if (!mod?.id || seen.has(mod.id)) return;
|
|
18
|
-
seen.add(mod.id);
|
|
19
|
-
if (mod?.id?.endsWith(".css")) {
|
|
20
|
-
cssFiles.set(mod?.url, mod?.id);
|
|
21
|
-
onCss?.(mod?.url);
|
|
22
|
-
}
|
|
23
|
-
mod?.importedModules?.forEach((imp: any) => walkModule(imp));
|
|
24
|
-
};
|
|
25
|
-
walkModule(pageModule);
|
|
26
|
-
return cssFiles;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function collectManifestCss(
|
|
30
|
-
manifest: Manifest,
|
|
31
|
-
root: string,
|
|
32
|
-
pagePath: string,
|
|
33
|
-
onCss?: (path: string, parentUrl: string) => void,
|
|
34
|
-
parentUrl?: string
|
|
35
|
-
) {
|
|
36
|
-
const relativePagePath = root !== "" && pagePath.startsWith(root.endsWith('/') ? root : root + '/')
|
|
37
|
-
? pagePath.slice(root.length + (root.endsWith('/') ? 0 : 1))
|
|
38
|
-
: pagePath;
|
|
39
|
-
const cssFiles = new Map<string, string>();
|
|
40
|
-
const seen = new Set<string>();
|
|
41
|
-
const manifestValues = Object.values(manifest);
|
|
42
|
-
const walkManifestEntry = (id: string) => {
|
|
43
|
-
if (seen.has(id)) return;
|
|
44
|
-
seen.add(id);
|
|
45
|
-
if (id.endsWith(".css")) {
|
|
46
|
-
cssFiles.set(id, id);
|
|
47
|
-
onCss?.(id, parentUrl ?? pagePath);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (id.endsWith(".css.js")) {
|
|
51
|
-
cssFiles.set(id.slice(0, -3), id.slice(0, -3));
|
|
52
|
-
onCss?.(id.slice(0, -3), parentUrl ?? pagePath);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// Get the manifest entry
|
|
56
|
-
const entry = manifest[id] ?? manifestValues.find(e => e.file === id);
|
|
57
|
-
if (!entry) return;
|
|
58
|
-
|
|
59
|
-
// Add direct CSS
|
|
60
|
-
if (entry.css) {
|
|
61
|
-
entry.css.forEach((css: string) => {
|
|
62
|
-
cssFiles.set(entry.src ?? entry.file ?? '', css);
|
|
63
|
-
onCss?.(css, parentUrl ?? pagePath);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Walk imports recursively
|
|
68
|
-
if (entry.imports) {
|
|
69
|
-
entry.imports.forEach((imp: string) => walkManifestEntry(imp));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Also check dynamicImports
|
|
73
|
-
if (entry.dynamicImports) {
|
|
74
|
-
entry.dynamicImports.forEach((imp: string) => walkManifestEntry(imp));
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (manifest[relativePagePath]) {
|
|
79
|
-
walkManifestEntry(relativePagePath);
|
|
80
|
-
}
|
|
81
|
-
return cssFiles;
|
|
82
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
2
|
-
|
|
3
|
-
export const createModuleIdGenerator = ({
|
|
4
|
-
inputRoot,
|
|
5
|
-
client,
|
|
6
|
-
server,
|
|
7
|
-
moduleBase,
|
|
8
|
-
isProduction,
|
|
9
|
-
preserveModulesRoot,
|
|
10
|
-
imports,
|
|
11
|
-
removeExtension
|
|
12
|
-
}: {
|
|
13
|
-
isProduction: boolean;
|
|
14
|
-
inputRoot: string;
|
|
15
|
-
client: string;
|
|
16
|
-
server: string;
|
|
17
|
-
moduleBase: string;
|
|
18
|
-
preserveModulesRoot: boolean;
|
|
19
|
-
removeExtension: ((path: string) => boolean) | string | RegExp;
|
|
20
|
-
imports: Record<string, string>;
|
|
21
|
-
}) => {
|
|
22
|
-
const normalizer = createInputNormalizer({
|
|
23
|
-
root: inputRoot,
|
|
24
|
-
removeExtension: removeExtension,
|
|
25
|
-
preserveModulesRoot: preserveModulesRoot === true ? moduleBase : undefined,
|
|
26
|
-
});
|
|
27
|
-
return (moduleIdPath: string, ssr = isProduction) => {
|
|
28
|
-
const [moduleId, modulePath] = normalizer(moduleIdPath);
|
|
29
|
-
const key = preserveModulesRoot ? `${moduleBase}/${moduleId}` : moduleId;
|
|
30
|
-
const hasImports = key in imports;
|
|
31
|
-
|
|
32
|
-
if (hasImports) {
|
|
33
|
-
// Return the actual file path from the manifest
|
|
34
|
-
const mappedImport = imports[key];
|
|
35
|
-
const noRoot = mappedImport.startsWith(inputRoot) ? mappedImport.slice(inputRoot.length +1) : mappedImport;
|
|
36
|
-
const noModuleBase = preserveModulesRoot ? noRoot.startsWith(moduleBase) ? noRoot.slice(moduleBase.length) : noRoot : noRoot;
|
|
37
|
-
return noModuleBase;
|
|
38
|
-
} else if (ssr && isProduction) {
|
|
39
|
-
// Only throw in production SSR builds
|
|
40
|
-
const availableImports =
|
|
41
|
-
Object.keys(imports).length > 0
|
|
42
|
-
? Object.keys(imports).join(", ")
|
|
43
|
-
: "none";
|
|
44
|
-
throw new Error(
|
|
45
|
-
`${availableImports === "none" ? "No imports." : `Module ID ${key}, ${modulePath} is not in imports. Available imports: ${availableImports}`}`
|
|
46
|
-
);
|
|
47
|
-
} else {
|
|
48
|
-
// For development or non-SSR builds, use the module ID
|
|
49
|
-
return moduleId;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_CONFIG = {
|
|
2
|
-
FILE_REGEX: /\.(m|c)?(j|t)sx?$/,
|
|
3
|
-
CLIENT_ASSETS_DIR: "assets",
|
|
4
|
-
RSC_DIR: "rsc",
|
|
5
|
-
MODULE_BASE: "src",
|
|
6
|
-
MODULE_BASE_PATH: "/src",
|
|
7
|
-
MODULE_BASE_URL: "/src",
|
|
8
|
-
PAGE: "src/page/page.tsx",
|
|
9
|
-
PROPS: "src/page/props.ts",
|
|
10
|
-
CLIENT_ENTRY: "src/client.tsx",
|
|
11
|
-
SERVER_ENTRY: "src/server.tsx",
|
|
12
|
-
PAGE_EXPORT_NAME: "Page",
|
|
13
|
-
PROPS_EXPORT_NAME: "props",
|
|
14
|
-
HTML_WORKER_PATH: `node_modules/vite-plugin-react-server/dist/plugin/worker/html/html-worker.${process.env['NODE_ENV'] === 'development' ? 'development' : 'production'}.js`,
|
|
15
|
-
RSC_WORKER_PATH: `node_modules/vite-plugin-react-server/dist/plugin/worker/rsc/rsc-worker.${process.env['NODE_ENV'] === 'development' ? 'development' : 'production'}.js`,
|
|
16
|
-
LOADER_PATH: 'node_modules/vite-plugin-react-server/dist/plugin/worker/loader.js',
|
|
17
|
-
RSC_EXTENSION: ".rsc",
|
|
18
|
-
HTML: ({ children }: { children: any }) => children,
|
|
19
|
-
COLLECT_CSS: true,
|
|
20
|
-
COLLECT_ASSETS: true,
|
|
21
|
-
DEV_PORT: 5173,
|
|
22
|
-
PREVIEW_PORT: 4173,
|
|
23
|
-
DEV_HOST: "localhost",
|
|
24
|
-
PREVIEW_HOST: "localhost",
|
|
25
|
-
ENV_PREFIX: "VITE_",
|
|
26
|
-
BUILD: {
|
|
27
|
-
pages: () => ["/"],
|
|
28
|
-
client: "client",
|
|
29
|
-
server: "server",
|
|
30
|
-
static: "static",
|
|
31
|
-
api: "api",
|
|
32
|
-
outDir: "dist",
|
|
33
|
-
assetsDir: "assets",
|
|
34
|
-
hash: "hash",
|
|
35
|
-
preserveModulesRoot: true,
|
|
36
|
-
},
|
|
37
|
-
MODULE_BASE_EXCEPTIONS: [] as string[],
|
|
38
|
-
AUTO_DISCOVER: {
|
|
39
|
-
modulePattern: (n: string) => DEFAULT_CONFIG.FILE_REGEX.test(n),
|
|
40
|
-
pagePattern: (n: string) => n.toLowerCase().endsWith('/page') || n.toLowerCase() === 'page',
|
|
41
|
-
propsPattern: (n: string) => n.toLowerCase().endsWith('/props') || n.toLowerCase() === 'props',
|
|
42
|
-
clientComponents: (n: string) => n.toLowerCase().endsWith('.client') || n.toLowerCase() === 'client',
|
|
43
|
-
serverFunctions: (n: string) => n.toLowerCase().endsWith('.server') || n.toLowerCase() === 'server',
|
|
44
|
-
cssPattern: (n: string) => n.toLowerCase().endsWith('.css'),
|
|
45
|
-
cssModulePattern: (n: string) => n.toLowerCase().endsWith('.css.js'),
|
|
46
|
-
vendorPattern: (n: string) => n.toLowerCase().startsWith('node_modules') || n.toLowerCase().startsWith('_virtual'),
|
|
47
|
-
htmlPattern: (n: string) => n.toLowerCase().endsWith('.html'),
|
|
48
|
-
jsonPattern: (n: string) => n.toLowerCase().endsWith('.json'),
|
|
49
|
-
},
|
|
50
|
-
MODULE_ID: (id: string) => id,
|
|
51
|
-
} as const;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { ModuleGraph, type Manifest } from "vite";
|
|
2
|
-
import {
|
|
3
|
-
collectManifestCss,
|
|
4
|
-
collectModuleGraphCss,
|
|
5
|
-
} from "../collect-css-manifest.js";
|
|
6
|
-
|
|
7
|
-
type BaseCssLoaderOptions = {
|
|
8
|
-
/** callback to add css files to the stream */
|
|
9
|
-
onCssFile: (css: string) => void;
|
|
10
|
-
/** loader to load the module */
|
|
11
|
-
loader: (id: string) => Promise<Record<string, any>>;
|
|
12
|
-
/** url of the page */
|
|
13
|
-
url: string;
|
|
14
|
-
/** manually provided css files to add */
|
|
15
|
-
cssFiles: string[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type CreateCssLoaderOptions =
|
|
19
|
-
| (BaseCssLoaderOptions & {
|
|
20
|
-
/** manifest to collect css from */
|
|
21
|
-
manifest: Manifest;
|
|
22
|
-
/** when manifest is given, moduleGraph is not needed */
|
|
23
|
-
moduleGraph?: never;
|
|
24
|
-
})
|
|
25
|
-
| (BaseCssLoaderOptions & {
|
|
26
|
-
/** when moduleGraph is given, manifest is not needed, manual cssFiles can still be provided */
|
|
27
|
-
manifest?: never;
|
|
28
|
-
/** when moduleGraph is given, manifest is not needed, manual cssFiles can still be provided */
|
|
29
|
-
moduleGraph: ModuleGraph;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* create a loader that can be used to load css files from a manifest or a moduleGraph
|
|
34
|
-
* @param options
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
export async function createCssLoader(options: CreateCssLoaderOptions) {
|
|
38
|
-
const root = process.cwd();
|
|
39
|
-
|
|
40
|
-
const cssModules = new Set<string>();
|
|
41
|
-
|
|
42
|
-
if (!(options.manifest || options.moduleGraph))
|
|
43
|
-
throw new Error("Missing manifest or moduleGraph, pass it to options.");
|
|
44
|
-
|
|
45
|
-
const getCss = options.manifest
|
|
46
|
-
? (id: string) =>
|
|
47
|
-
collectManifestCss(
|
|
48
|
-
options.manifest,
|
|
49
|
-
root,
|
|
50
|
-
id,
|
|
51
|
-
options.onCssFile
|
|
52
|
-
)
|
|
53
|
-
: (id: string) => collectModuleGraphCss(options.moduleGraph!, id, options.onCssFile);
|
|
54
|
-
|
|
55
|
-
const loadWithCss = async (id: string) => {
|
|
56
|
-
if (!id) return {};
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const mod = await options.loader(id);
|
|
60
|
-
const pageCss = await Promise.resolve(getCss(id));
|
|
61
|
-
Array.from(pageCss.keys()).forEach((css) => cssModules.add(css));
|
|
62
|
-
return mod as Record<string, any>;
|
|
63
|
-
} catch (e: any) {
|
|
64
|
-
if (e.message?.includes("module runner has been closed")) {
|
|
65
|
-
return { type: "skip" } as Record<string, any>;
|
|
66
|
-
} else {
|
|
67
|
-
return { type: "error", error: e } as Record<string, any>;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return loadWithCss;
|
|
73
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { resolve as resolvePath } from "node:path";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
load
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
} from "react-server-dom-esm/node-loader";
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
registerClientReference,
|
|
10
|
-
registerServerReference,
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
} from "react-server-dom-esm/server.node";
|
|
13
|
-
|
|
14
|
-
type CreatePageLoaderOptions = {
|
|
15
|
-
manifest: Record<string, { file: string; src?: string }>;
|
|
16
|
-
root: string;
|
|
17
|
-
outDir: string;
|
|
18
|
-
moduleBase: string;
|
|
19
|
-
registerServer?: string[];
|
|
20
|
-
registerClient?: string[];
|
|
21
|
-
alwaysRegisterServer?: boolean;
|
|
22
|
-
alwaysRegisterClient?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
type CreateDefaultLoaderOptions = {
|
|
26
|
-
id: string;
|
|
27
|
-
registerServer?: string[];
|
|
28
|
-
registerClient?: string[];
|
|
29
|
-
alwaysRegisterServer?: boolean;
|
|
30
|
-
alwaysRegisterClient?: boolean;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const createDefaultLoader = ({
|
|
34
|
-
id,
|
|
35
|
-
registerServer,
|
|
36
|
-
registerClient,
|
|
37
|
-
alwaysRegisterServer = false,
|
|
38
|
-
alwaysRegisterClient = false,
|
|
39
|
-
}: CreateDefaultLoaderOptions) => {
|
|
40
|
-
const mapper = ([key, value]: [string, any]) => {
|
|
41
|
-
try {
|
|
42
|
-
if (
|
|
43
|
-
registerClient?.includes(key) ||
|
|
44
|
-
(alwaysRegisterClient && typeof value === "function")
|
|
45
|
-
) {
|
|
46
|
-
return [key, registerClientReference(value, id, key)];
|
|
47
|
-
}
|
|
48
|
-
if (
|
|
49
|
-
registerServer?.includes(key) ||
|
|
50
|
-
(alwaysRegisterServer && typeof value === "function")
|
|
51
|
-
) {
|
|
52
|
-
return [key, registerServerReference(value, id, key)];
|
|
53
|
-
}
|
|
54
|
-
return [key, value];
|
|
55
|
-
} catch (e) {
|
|
56
|
-
console.error("[RSC] Error registering reference:", key, value, e);
|
|
57
|
-
return [key, value];
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
return async (url: string) => {
|
|
61
|
-
console.log("[createDefaultLoader] Loading:", url);
|
|
62
|
-
const result = await import(url);
|
|
63
|
-
console.log("[createDefaultLoader] Result:", result);
|
|
64
|
-
return Object.fromEntries(Object.entries(result).map(mapper));
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export function createPageLoader({
|
|
69
|
-
manifest,
|
|
70
|
-
root,
|
|
71
|
-
outDir,
|
|
72
|
-
moduleBase,
|
|
73
|
-
alwaysRegisterServer,
|
|
74
|
-
alwaysRegisterClient,
|
|
75
|
-
registerServer,
|
|
76
|
-
registerClient,
|
|
77
|
-
}: CreatePageLoaderOptions) {
|
|
78
|
-
return async function loader(id: string) {
|
|
79
|
-
|
|
80
|
-
// Try to find the entry directly or by source file
|
|
81
|
-
const manifestEntry = manifest[id] ||
|
|
82
|
-
Object.values(manifest).find(entry => entry.src === id);
|
|
83
|
-
|
|
84
|
-
if (!manifestEntry) {
|
|
85
|
-
throw new Error(
|
|
86
|
-
`Could not find manifest entry for ${id} from ${root}. Available entries: ${Object.keys(manifest).join(', ')}`
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const loaderResult = await load(
|
|
91
|
-
resolvePath(root, outDir, manifestEntry.file),
|
|
92
|
-
{ format: "module" },
|
|
93
|
-
createDefaultLoader({
|
|
94
|
-
id,
|
|
95
|
-
registerServer,
|
|
96
|
-
registerClient,
|
|
97
|
-
alwaysRegisterServer,
|
|
98
|
-
alwaysRegisterClient,
|
|
99
|
-
})
|
|
100
|
-
);
|
|
101
|
-
return loaderResult;
|
|
102
|
-
};
|
|
103
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { renderToPipeableStream } from "react-server-dom-esm/server.node";
|
|
4
|
-
import type { PipeableStreamOptions } from "../worker/types.js";
|
|
5
|
-
import type { Logger } from "vite";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// CSS collector component
|
|
9
|
-
function CssCollector({
|
|
10
|
-
children,
|
|
11
|
-
cssFiles,
|
|
12
|
-
}: {
|
|
13
|
-
children?: React.ReactNode;
|
|
14
|
-
cssFiles: string[];
|
|
15
|
-
}) {
|
|
16
|
-
return React.createElement(
|
|
17
|
-
React.Fragment,
|
|
18
|
-
null,
|
|
19
|
-
...cssFiles.map((css) => {
|
|
20
|
-
const url = css.startsWith('/') || css.startsWith('http') || css.startsWith('./') ? css : '/'+css
|
|
21
|
-
return React.createElement('link', {
|
|
22
|
-
key: css,
|
|
23
|
-
rel: 'stylesheet',
|
|
24
|
-
href: url,
|
|
25
|
-
precedence: 'high'
|
|
26
|
-
})
|
|
27
|
-
}),
|
|
28
|
-
children
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createRscStream({
|
|
33
|
-
Html,
|
|
34
|
-
Page,
|
|
35
|
-
props,
|
|
36
|
-
moduleBasePath,
|
|
37
|
-
logger,
|
|
38
|
-
cssFiles = [],
|
|
39
|
-
route,
|
|
40
|
-
url,
|
|
41
|
-
pipableStreamOptions,
|
|
42
|
-
htmlProps,
|
|
43
|
-
}: {
|
|
44
|
-
Html: React.ComponentType<any>;
|
|
45
|
-
Page: React.ComponentType<any>;
|
|
46
|
-
props: any;
|
|
47
|
-
moduleBasePath: string;
|
|
48
|
-
logger: Logger;
|
|
49
|
-
cssFiles?: string[];
|
|
50
|
-
route: string;
|
|
51
|
-
url: string;
|
|
52
|
-
pipableStreamOptions?: PipeableStreamOptions;
|
|
53
|
-
htmlProps?: any;
|
|
54
|
-
}) {
|
|
55
|
-
|
|
56
|
-
const htmlIsFragment = Html == React.Fragment;
|
|
57
|
-
const withCss = React.createElement(
|
|
58
|
-
CssCollector,
|
|
59
|
-
{ cssFiles },
|
|
60
|
-
React.createElement(Page, props)
|
|
61
|
-
)
|
|
62
|
-
// Otherwise wrap with Html component
|
|
63
|
-
const content = htmlIsFragment
|
|
64
|
-
? withCss
|
|
65
|
-
: React.createElement(Html, htmlProps, withCss);
|
|
66
|
-
try {
|
|
67
|
-
return renderToPipeableStream(
|
|
68
|
-
content,
|
|
69
|
-
moduleBasePath,
|
|
70
|
-
{
|
|
71
|
-
onError: (error: Error) => {
|
|
72
|
-
if(process.env['NODE_ENV'] === 'development') {
|
|
73
|
-
console.trace(error);
|
|
74
|
-
}
|
|
75
|
-
logger.error(`Stream error at ${route}.`, {error});
|
|
76
|
-
},
|
|
77
|
-
onPostpone: logger.info ?? console.info,
|
|
78
|
-
environmentName: "Server",
|
|
79
|
-
...pipableStreamOptions,
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
logger.error(`Failed to create stream for ${route}.`, {error: error as Error});
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { join, resolve } from "node:path";
|
|
2
|
-
import { Writable } from "node:stream";
|
|
3
|
-
import { Worker } from "node:worker_threads";
|
|
4
|
-
import { type Manifest, type ViteDevServer } from "vite";
|
|
5
|
-
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
6
|
-
import type { RequestHandler, ResolvedUserOptions } from "../types.js";
|
|
7
|
-
import type { WorkerRscChunkMessage } from "../worker/types.js";
|
|
8
|
-
import { createHandler } from "./createHandler.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export function createSsrHandler(
|
|
12
|
-
options: ResolvedUserOptions,
|
|
13
|
-
server: ViteDevServer,
|
|
14
|
-
): RequestHandler {
|
|
15
|
-
const worker = new Worker(
|
|
16
|
-
options?.htmlWorkerPath
|
|
17
|
-
? resolve(server.config.root, options?.htmlWorkerPath)
|
|
18
|
-
: DEFAULT_CONFIG.HTML_WORKER_PATH,
|
|
19
|
-
{
|
|
20
|
-
env: {
|
|
21
|
-
NODE_OPTIONS: "--conditions ''",
|
|
22
|
-
VITE_LOADER_PATH: resolve(
|
|
23
|
-
server.config.cacheDir,
|
|
24
|
-
"react-stream/worker/loader.js"
|
|
25
|
-
),
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return async function handleSsrRequest(req, res, next) {
|
|
31
|
-
if (
|
|
32
|
-
!req.url ||
|
|
33
|
-
req.url.startsWith("/@") ||
|
|
34
|
-
(req.url.includes(".") && !req.url.endsWith(".html"))
|
|
35
|
-
) {
|
|
36
|
-
return next();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const result = await createHandler(
|
|
41
|
-
req.url ?? "",
|
|
42
|
-
{
|
|
43
|
-
...options,
|
|
44
|
-
projectRoot: server.config.root,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
loader: server.ssrLoadModule.bind(server),
|
|
48
|
-
moduleGraph: server.moduleGraph,
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
const moduleRootPath = join(
|
|
52
|
-
server.config.cacheDir,
|
|
53
|
-
options.moduleBasePath
|
|
54
|
-
);
|
|
55
|
-
// const htmlOutputPath = join(
|
|
56
|
-
// server.config.cacheDir,
|
|
57
|
-
// server.config.build.outDir,
|
|
58
|
-
// req.url,
|
|
59
|
-
// "index.html"
|
|
60
|
-
// );
|
|
61
|
-
if (result.type !== "success") {
|
|
62
|
-
throw new Error(
|
|
63
|
-
result.type === "error" ? String(result.error) : "Skipped"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Collect RSC stream data
|
|
68
|
-
const rscData = await new Promise<string>((resolve, reject) => {
|
|
69
|
-
let data = "";
|
|
70
|
-
if (!result.stream) {
|
|
71
|
-
resolve(data);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const writable = new Writable({
|
|
75
|
-
write(chunk, _, callback) {
|
|
76
|
-
data += chunk;
|
|
77
|
-
callback();
|
|
78
|
-
},
|
|
79
|
-
final(callback) {
|
|
80
|
-
resolve(data);
|
|
81
|
-
callback();
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
result.stream.pipe(writable);
|
|
86
|
-
writable.on("error", reject);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Get HTML from worker
|
|
90
|
-
const html = await new Promise<string>((resolve, reject) => {
|
|
91
|
-
worker.postMessage({
|
|
92
|
-
type: "RSC_CHUNK",
|
|
93
|
-
id: req.url ?? "/",
|
|
94
|
-
chunk: rscData,
|
|
95
|
-
moduleRootPath: moduleRootPath,
|
|
96
|
-
moduleBaseURL: options.moduleBaseURL,
|
|
97
|
-
// Don't need file paths in dev mode
|
|
98
|
-
outDir: "",
|
|
99
|
-
htmlOutputPath: "",
|
|
100
|
-
pipableStreamOptions: options.pipableStreamOptions ?? {},
|
|
101
|
-
clientManifest: {},
|
|
102
|
-
serverManifest: {},
|
|
103
|
-
} satisfies WorkerRscChunkMessage);
|
|
104
|
-
|
|
105
|
-
worker.once("message", (msg) => {
|
|
106
|
-
if (msg.type === "ERROR") {
|
|
107
|
-
const message =
|
|
108
|
-
msg.error instanceof Error
|
|
109
|
-
? msg.error.message
|
|
110
|
-
: String(msg.error);
|
|
111
|
-
reject(new Error(message, { cause: msg }));
|
|
112
|
-
} else if (msg.type === "HTML") {
|
|
113
|
-
// In dev, content will be the HTML string
|
|
114
|
-
resolve(msg.content);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
res.setHeader("Content-Type", "text/html");
|
|
120
|
-
res.end(html);
|
|
121
|
-
} catch (error) {
|
|
122
|
-
next(error);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|