vite-plugin-react-server 0.3.18 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -141
- package/bin/patch.mjs +8 -2
- package/dist/package.json +15 -8
- 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 +131 -0
- package/dist/plugin/collect-manifest-client-files.js.map +1 -0
- package/dist/plugin/components.d.ts +3 -13
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +3 -13
- package/dist/plugin/config/defaults.d.ts +14 -6
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +9 -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 +2 -2
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +47 -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 +181 -147
- 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/css-collector-inline.d.ts +10 -0
- package/dist/plugin/css-collector-inline.d.ts.map +1 -0
- package/dist/plugin/css-collector-inline.js +55 -0
- package/dist/plugin/css-collector-inline.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +14 -0
- package/dist/plugin/css-collector.d.ts.map +1 -0
- package/dist/plugin/css-collector.js +49 -0
- package/dist/plugin/css-collector.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +17 -0
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createHandler.js +111 -0
- package/dist/plugin/helpers/createHandler.js.map +1 -0
- package/dist/plugin/helpers/createRscStream.d.ts +27 -0
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -0
- package/dist/plugin/helpers/createRscStream.js +80 -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/html.d.ts +5 -0
- package/dist/plugin/html.d.ts.map +1 -0
- package/dist/plugin/html.js +11 -0
- package/dist/plugin/html.js.map +1 -0
- 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 +21 -78
- 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 +92 -225
- 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 +207 -0
- package/dist/plugin/react-static/plugin.js.map +1 -0
- package/dist/plugin/react-static/types.d.ts +2 -0
- package/dist/plugin/react-static/types.d.ts.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 +70 -15
- 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 +12 -3
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts +13 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +138 -86
- 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 +104 -84
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- 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/plugin/worker/types.d.ts +3 -0
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -6
- package/plugin/checkFilesExist.ts +7 -3
- package/plugin/collect-manifest-client-files.ts +167 -0
- package/plugin/components.ts +3 -0
- package/plugin/config/defaults.tsx +70 -0
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/mimeTypes.ts +17 -0
- package/plugin/config/resolveOptions.ts +58 -45
- package/plugin/config/resolvePages.ts +8 -4
- package/plugin/config/resolveUserConfig.ts +220 -176
- package/plugin/css-collector-inline.tsx +60 -0
- package/plugin/css-collector.tsx +62 -0
- package/plugin/helpers/createHandler.ts +135 -0
- package/plugin/helpers/createRscStream.ts +109 -0
- package/plugin/helpers/getBundleManifest.ts +14 -5
- package/plugin/html.tsx +9 -0
- 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 +23 -93
- package/plugin/react-server/index.ts +2 -0
- package/plugin/react-server/plugin.ts +111 -302
- package/plugin/react-static/index.ts +1 -0
- package/plugin/react-static/plugin.ts +256 -0
- package/plugin/react-static/types.ts +3 -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 +77 -16
- 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 +12 -3
- package/plugin/worker/html/renderPages.ts +178 -138
- package/plugin/worker/rsc/README.md +58 -0
- package/plugin/worker/rsc/messageHandler.tsx +112 -113
- 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/plugin/worker/types.ts +3 -0
- 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/getEnv.d.ts +0 -19
- package/dist/plugin/getEnv.d.ts.map +0 -1
- package/dist/plugin/getEnv.js +0 -107
- 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/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/module-graph.d.ts +0 -10
- package/dist/plugin/module-graph.d.ts.map +0 -1
- package/dist/plugin/module-graph.js +0 -35
- 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 +0 -126
- package/dist/plugin/react-server/createHandler.js.map +0 -1
- package/dist/plugin/react-server/createRscStream.d.ts +0 -16
- 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/dist/plugin/worker/html/plugin.d.ts +0 -4
- package/dist/plugin/worker/html/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/html/plugin.js +0 -94
- package/dist/plugin/worker/plugin.d.ts +0 -19
- package/dist/plugin/worker/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/plugin.js +0 -23
- package/dist/plugin/worker/rsc/plugin.d.ts +0 -4
- package/dist/plugin/worker/rsc/plugin.d.ts.map +0 -1
- package/dist/plugin/worker/rsc/plugin.js +0 -76
- package/plugin/collect-css-manifest.ts +0 -82
- package/plugin/components.tsx +0 -14
- package/plugin/config/createModuleIdGenerator.ts +0 -52
- package/plugin/config/defaults.ts +0 -51
- package/plugin/getEnv.ts +0 -135
- 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/module-graph.ts +0 -48
- package/plugin/react-server/createHandler.ts +0 -162
- package/plugin/react-server/createRscStream.ts +0 -86
- package/plugin/react-server/createSsrHandler.ts +0 -125
- package/plugin/utils/logger.ts +0 -52
- package/plugin/worker/html/plugin.ts +0 -101
- package/plugin/worker/plugin.ts +0 -26
- package/plugin/worker/rsc/plugin.ts +0 -84
- /package/dist/plugin/{loader/rsc/messageHandler.js → react-static/types.js} +0 -0
|
@@ -9,8 +9,13 @@ import { join } from "path";
|
|
|
9
9
|
// @ts-ignore
|
|
10
10
|
import { globSync } from "fs";
|
|
11
11
|
import type { OutputOptions } from "rollup";
|
|
12
|
+
import { pluginRoot } from "../root.js";
|
|
13
|
+
|
|
14
|
+
let stashedUserConfig: Record<string, ResolvedUserConfig | null> = {};
|
|
15
|
+
|
|
12
16
|
export type ResolveUserConfigProps = {
|
|
13
17
|
isClient?: boolean;
|
|
18
|
+
isStatic?: boolean;
|
|
14
19
|
config: UserConfig;
|
|
15
20
|
configEnv: ConfigEnv;
|
|
16
21
|
userOptions: ResolvedUserOptions;
|
|
@@ -23,208 +28,247 @@ export type ResolveUserConfigReturn =
|
|
|
23
28
|
|
|
24
29
|
export function resolveUserConfig({
|
|
25
30
|
isClient = false,
|
|
31
|
+
isStatic = false,
|
|
26
32
|
config,
|
|
27
33
|
configEnv,
|
|
28
34
|
userOptions,
|
|
29
35
|
files,
|
|
30
36
|
}: ResolveUserConfigProps): ResolveUserConfigReturn {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
if(isStatic) {
|
|
38
|
+
const serverConfig = stashedUserConfig[`${userOptions.build.server}-ssr`]
|
|
39
|
+
if(!serverConfig) {
|
|
40
|
+
return {
|
|
41
|
+
type: "error",
|
|
42
|
+
error: new Error("Static plugin should run after the server plugin"),
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
type: "success",
|
|
47
|
+
userConfig: serverConfig,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const envDir = isStatic
|
|
51
|
+
? userOptions.build.static
|
|
52
|
+
: isClient
|
|
53
|
+
? userOptions.build.client
|
|
54
|
+
: userOptions.build.server;
|
|
55
|
+
const ssr =
|
|
56
|
+
typeof config.build?.ssr === "boolean"
|
|
57
|
+
? config.build?.ssr
|
|
58
|
+
: configEnv.isSsrBuild || (!isClient && !isStatic);
|
|
59
|
+
const envId = `${envDir}${ssr ? "-ssr" : ""}`;
|
|
60
|
+
if (stashedUserConfig[envId]) {
|
|
61
|
+
console.log(`[RSC] Using cached config for ${envId}`);
|
|
62
|
+
return {
|
|
63
|
+
type: "success",
|
|
64
|
+
userConfig: stashedUserConfig[envId],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Get existing inputs
|
|
68
|
+
const root = config.root ?? userOptions.projectRoot ?? process.cwd();
|
|
34
69
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
70
|
+
const normalizer = createInputNormalizer({
|
|
71
|
+
root,
|
|
72
|
+
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
73
|
+
? userOptions.moduleBase
|
|
74
|
+
: undefined,
|
|
75
|
+
removeExtension: true,
|
|
76
|
+
});
|
|
42
77
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
78
|
+
const serverEntry = userOptions.serverEntry
|
|
79
|
+
? Object.fromEntries([
|
|
80
|
+
normalizer([userOptions.serverEntry, userOptions.serverEntry]),
|
|
81
|
+
])
|
|
82
|
+
: null;
|
|
83
|
+
const clientEntry = userOptions.clientEntry
|
|
84
|
+
? Object.fromEntries(
|
|
85
|
+
[
|
|
86
|
+
[userOptions.clientEntry, userOptions.clientEntry],
|
|
87
|
+
["index.html", "index.html"],
|
|
88
|
+
].map(normalizer)
|
|
89
|
+
)
|
|
90
|
+
: { "index.html": "index.html" };
|
|
56
91
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
92
|
+
const autoDiscoveredClientFiles = (inputs: Record<string, string>) => {
|
|
93
|
+
const allFiles = globSync(`**/*.client.*`, {
|
|
94
|
+
cwd: join(root, userOptions.moduleBase),
|
|
95
|
+
});
|
|
61
96
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
97
|
+
for (const file of allFiles) {
|
|
98
|
+
const [key, value] = normalizer(join(userOptions.moduleBase, file));
|
|
99
|
+
if (!inputs[key]) {
|
|
100
|
+
inputs[key] = value;
|
|
101
|
+
} else {
|
|
102
|
+
console.warn(`[RSC] Client file already exists: ${key}`);
|
|
69
103
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
104
|
+
}
|
|
105
|
+
return inputs;
|
|
106
|
+
};
|
|
107
|
+
const autoDiscoveredServerFiles = (inputs: Record<string, string>) => {
|
|
108
|
+
const allFiles = globSync(`${userOptions.moduleBase}/**/*.server.*`, {
|
|
109
|
+
cwd: join(root, userOptions.moduleBase),
|
|
110
|
+
});
|
|
111
|
+
for (const file of allFiles) {
|
|
112
|
+
const [key, value] = normalizer(join(userOptions.moduleBase, file));
|
|
113
|
+
if (!inputs[key]) {
|
|
114
|
+
inputs[key] = value;
|
|
115
|
+
} else {
|
|
116
|
+
console.warn(`[RSC] Server file already exists: ${key}`);
|
|
83
117
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
118
|
+
}
|
|
119
|
+
return inputs;
|
|
120
|
+
};
|
|
121
|
+
const customWorkerFiles = (inputs: Record<string, string>) => {
|
|
122
|
+
const customRscWorker = !userOptions.rscWorkerPath.startsWith(pluginRoot)
|
|
123
|
+
const customHtmlWorker = !userOptions.htmlWorkerPath.startsWith(pluginRoot)
|
|
124
|
+
if(customRscWorker && !inputs['rsc-worker']) {
|
|
125
|
+
inputs['rsc-worker'] = userOptions.rscWorkerPath
|
|
126
|
+
}
|
|
127
|
+
if(customHtmlWorker && !inputs['html-worker']) {
|
|
128
|
+
inputs['html-worker'] = userOptions.htmlWorkerPath
|
|
129
|
+
}
|
|
130
|
+
return inputs
|
|
131
|
+
}
|
|
132
|
+
const autoDiscoveredFiles = (inputs: Record<string, string>) => {
|
|
133
|
+
if (!files) return inputs;
|
|
88
134
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
135
|
+
// Add page files without extra prefix
|
|
136
|
+
for (const [key, value] of files.pageMap) {
|
|
137
|
+
if (!inputs[key]) {
|
|
138
|
+
inputs[key] = value;
|
|
139
|
+
} else {
|
|
140
|
+
console.warn(`[RSC] Page file already exists: ${key}`);
|
|
96
141
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
142
|
+
}
|
|
143
|
+
// Add props files without extra prefix
|
|
144
|
+
for (const [key, value] of files.propsMap) {
|
|
145
|
+
if (!inputs[key]) {
|
|
146
|
+
inputs[key] = value;
|
|
147
|
+
} else {
|
|
148
|
+
console.warn(`[RSC] Props file already exists: ${key}`);
|
|
104
149
|
}
|
|
105
|
-
|
|
106
|
-
|
|
150
|
+
}
|
|
151
|
+
return inputs;
|
|
152
|
+
};
|
|
107
153
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
154
|
+
// Add inputs based on condition
|
|
155
|
+
let inputs = isClient
|
|
156
|
+
? autoDiscoveredClientFiles(clientEntry)
|
|
157
|
+
: customWorkerFiles(autoDiscoveredServerFiles(autoDiscoveredFiles(serverEntry ?? {})));
|
|
112
158
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
159
|
+
const pluginOutput = {
|
|
160
|
+
preserveModules: !isClient,
|
|
161
|
+
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
162
|
+
? userOptions.moduleBase
|
|
163
|
+
: undefined,
|
|
164
|
+
entryFileNames: userOptions.build.entryFile,
|
|
165
|
+
assetFileNames: userOptions.build.assetFile,
|
|
166
|
+
chunkFileNames: userOptions.build.chunkFile,
|
|
167
|
+
format: "esm",
|
|
168
|
+
exports: "named",
|
|
169
|
+
hoistTransitiveImports: false,
|
|
170
|
+
generatedCode: {
|
|
171
|
+
constBindings: true,
|
|
172
|
+
objectShorthand: true,
|
|
173
|
+
},
|
|
174
|
+
interop: "auto",
|
|
175
|
+
} satisfies OutputOptions;
|
|
116
176
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
assetFileNames: userOptions.build.assetFile,
|
|
124
|
-
chunkFileNames: userOptions.build.chunkFile,
|
|
125
|
-
format: "esm",
|
|
126
|
-
exports: "named",
|
|
127
|
-
hoistTransitiveImports: false,
|
|
128
|
-
generatedCode: {
|
|
129
|
-
constBindings: true,
|
|
130
|
-
objectShorthand: true,
|
|
131
|
-
},
|
|
132
|
-
interop: "auto",
|
|
133
|
-
} satisfies OutputOptions;
|
|
134
|
-
|
|
135
|
-
const newOutput = Array.isArray(config.build?.rollupOptions?.output)
|
|
136
|
-
? [...config.build?.rollupOptions?.output, pluginOutput]
|
|
137
|
-
: typeof config.build?.rollupOptions?.output === "object" &&
|
|
138
|
-
config.build?.rollupOptions?.output !== null
|
|
139
|
-
? [config.build?.rollupOptions?.output, pluginOutput]
|
|
140
|
-
: pluginOutput;
|
|
177
|
+
let newOutput = Array.isArray(config.build?.rollupOptions?.output)
|
|
178
|
+
? [...config.build?.rollupOptions?.output, pluginOutput]
|
|
179
|
+
: typeof config.build?.rollupOptions?.output === "object" &&
|
|
180
|
+
config.build?.rollupOptions?.output !== null
|
|
181
|
+
? [config.build?.rollupOptions?.output, pluginOutput]
|
|
182
|
+
: pluginOutput;
|
|
141
183
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
"react-dom",
|
|
159
|
-
"react-server-dom-esm/client.browser",
|
|
160
|
-
],
|
|
161
|
-
resolve: {
|
|
162
|
-
externalConditions: ["react-server"],
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
// client build options
|
|
166
|
-
build: {
|
|
167
|
-
...config.build,
|
|
168
|
-
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
169
|
-
outDir: join(userOptions.build.outDir, envDir),
|
|
170
|
-
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
171
|
-
// modern browsers
|
|
172
|
-
target: ["esnext"],
|
|
173
|
-
minify: true,
|
|
174
|
-
ssr:
|
|
175
|
-
typeof configEnv.isSsrBuild === "boolean"
|
|
176
|
-
? configEnv.isSsrBuild
|
|
177
|
-
: true,
|
|
178
|
-
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
179
|
-
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
180
|
-
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
181
|
-
rollupOptions: {
|
|
182
|
-
...config.build?.rollupOptions,
|
|
183
|
-
input: inputs,
|
|
184
|
-
output: newOutput,
|
|
185
|
-
preserveEntrySignatures: "exports-only",
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
// server build options
|
|
192
|
-
return {
|
|
193
|
-
type: "success",
|
|
194
|
-
userConfig: {
|
|
195
|
-
...config,
|
|
196
|
-
root: root,
|
|
197
|
-
mode: configEnv.mode ?? configEnv.command === "build" ? "production" : "development",
|
|
184
|
+
if (isClient) {
|
|
185
|
+
// client plugin build options (client plugin still outputs server files)
|
|
186
|
+
stashedUserConfig[envId] = {
|
|
187
|
+
...config,
|
|
188
|
+
root: root,
|
|
189
|
+
mode:
|
|
190
|
+
configEnv.mode ?? configEnv.command === "build"
|
|
191
|
+
? "production"
|
|
192
|
+
: "development",
|
|
193
|
+
resolve: {
|
|
194
|
+
external: ["react", "react-dom"],
|
|
195
|
+
alias: {},
|
|
196
|
+
},
|
|
197
|
+
ssr: {
|
|
198
|
+
target: "node",
|
|
199
|
+
external: ["react", "react-dom", "react-server-dom-esm/client.browser"],
|
|
198
200
|
resolve: {
|
|
199
|
-
alias: {},
|
|
200
201
|
externalConditions: ["react-server"],
|
|
201
202
|
},
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
203
|
+
},
|
|
204
|
+
// client build options
|
|
205
|
+
build: {
|
|
206
|
+
...config.build,
|
|
207
|
+
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
208
|
+
outDir: join(userOptions.build.outDir, envDir),
|
|
209
|
+
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
210
|
+
copyPublicDir: config.build?.copyPublicDir ?? true,
|
|
211
|
+
// modern browsers
|
|
212
|
+
target: ["esnext"],
|
|
213
|
+
minify: true,
|
|
214
|
+
ssr: ssr,
|
|
215
|
+
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
216
|
+
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
217
|
+
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
218
|
+
rollupOptions: {
|
|
219
|
+
...config.build?.rollupOptions,
|
|
220
|
+
input: inputs,
|
|
221
|
+
output: newOutput,
|
|
222
|
+
preserveEntrySignatures: "exports-only",
|
|
220
223
|
},
|
|
221
224
|
},
|
|
222
225
|
};
|
|
223
|
-
}
|
|
226
|
+
} else {
|
|
227
|
+
// server build options
|
|
228
|
+
if (configEnv.isSsrBuild === false) {
|
|
229
|
+
configEnv.isSsrBuild = true;
|
|
230
|
+
}
|
|
231
|
+
stashedUserConfig[envId] = {
|
|
232
|
+
...config,
|
|
233
|
+
root: root,
|
|
234
|
+
mode:
|
|
235
|
+
configEnv.mode ?? configEnv.command === "build"
|
|
236
|
+
? "production"
|
|
237
|
+
: "development",
|
|
238
|
+
resolve: {
|
|
239
|
+
externalConditions: ["react-server"],
|
|
240
|
+
},
|
|
241
|
+
// server build options
|
|
242
|
+
build: {
|
|
243
|
+
...config.build,
|
|
244
|
+
emptyOutDir: config.build?.emptyOutDir ?? true,
|
|
245
|
+
outDir: join(userOptions.build.outDir, envDir),
|
|
246
|
+
target: config.build?.target ?? "node18",
|
|
247
|
+
minify: config.build?.minify ?? true,
|
|
248
|
+
ssr: ssr,
|
|
249
|
+
manifest: config.build?.manifest ?? `.vite/manifest.json`,
|
|
250
|
+
ssrManifest: config.build?.ssrManifest ?? `.vite/ssr-manifest.json`,
|
|
251
|
+
ssrEmitAssets: config.build?.ssrEmitAssets ?? true,
|
|
252
|
+
copyPublicDir: config.build?.copyPublicDir ?? isStatic,
|
|
253
|
+
assetsDir: config.build?.assetsDir ?? userOptions.build.assetsDir,
|
|
254
|
+
rollupOptions: {
|
|
255
|
+
...config.build?.rollupOptions,
|
|
256
|
+
input: inputs,
|
|
257
|
+
preserveEntrySignatures:
|
|
258
|
+
config.build?.rollupOptions?.preserveEntrySignatures ?? "strict",
|
|
259
|
+
output: newOutput,
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
if (!stashedUserConfig[envId]) {
|
|
224
265
|
return {
|
|
225
266
|
type: "error",
|
|
226
|
-
error:
|
|
227
|
-
error instanceof Error ? error : new Error("Failed to resolve config"),
|
|
267
|
+
error: new Error("Failed to resolve config"),
|
|
228
268
|
};
|
|
229
269
|
}
|
|
270
|
+
return {
|
|
271
|
+
type: "success",
|
|
272
|
+
userConfig: stashedUserConfig[envId],
|
|
273
|
+
};
|
|
230
274
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { InlineCssCollectorProps } from "./types.js";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
interface CssContent {
|
|
7
|
+
type?: string;
|
|
8
|
+
content: string;
|
|
9
|
+
key?: string;
|
|
10
|
+
path: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A component that inlines pre-transformed CSS content.
|
|
15
|
+
* Expects cssFiles to be an array of CssContent objects with the content already loaded.
|
|
16
|
+
*/
|
|
17
|
+
export function InlineCssCollector({
|
|
18
|
+
children,
|
|
19
|
+
cssFiles,
|
|
20
|
+
moduleRootPath,
|
|
21
|
+
}: InlineCssCollectorProps) {
|
|
22
|
+
return React.createElement(
|
|
23
|
+
React.Fragment,
|
|
24
|
+
null,
|
|
25
|
+
cssFiles.map((file, index) => {
|
|
26
|
+
if (typeof file === "string") {
|
|
27
|
+
let filePath = file as string;
|
|
28
|
+
if(process.env["NODE_ENV"] === "development") {
|
|
29
|
+
return React.createElement("link", {
|
|
30
|
+
key: file,
|
|
31
|
+
rel: "stylesheet",
|
|
32
|
+
href: filePath,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return React.createElement(
|
|
36
|
+
"style",
|
|
37
|
+
{
|
|
38
|
+
key: file,
|
|
39
|
+
type: "text/css",
|
|
40
|
+
},
|
|
41
|
+
readFileSync(join(moduleRootPath, filePath), "utf-8")
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { type, content, key, path } = file as CssContent;
|
|
46
|
+
return React.createElement(
|
|
47
|
+
"style",
|
|
48
|
+
{
|
|
49
|
+
key: key ?? path ?? index,
|
|
50
|
+
type: type ?? "text/css",
|
|
51
|
+
...(process.env["NODE_ENV"] === "development" && {
|
|
52
|
+
"data-vite-dev-id": join(moduleRootPath, path),
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
content
|
|
56
|
+
);
|
|
57
|
+
}),
|
|
58
|
+
children
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A component that emits <link> tags for CSS files during streaming.
|
|
6
|
+
* The high precedence ensures they bubble up to the document head.
|
|
7
|
+
*/
|
|
8
|
+
export function CssCollector({
|
|
9
|
+
children,
|
|
10
|
+
cssFiles,
|
|
11
|
+
moduleBaseURL,
|
|
12
|
+
route = "/",
|
|
13
|
+
}: {
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
cssFiles: string[];
|
|
16
|
+
moduleBaseURL?: string;
|
|
17
|
+
route?: string;
|
|
18
|
+
}) {
|
|
19
|
+
// Calculate depth and prefix based on route
|
|
20
|
+
const depth = route.split('/').filter(Boolean).length;
|
|
21
|
+
const prefix = depth > 0 ? '../'.repeat(depth) : './';
|
|
22
|
+
const base = typeof moduleBaseURL === 'string' && moduleBaseURL !== '' ? moduleBaseURL : prefix;
|
|
23
|
+
|
|
24
|
+
const elements = cssFiles.map((file) => {
|
|
25
|
+
// Handle pre-processed CSS content - skip in link mode
|
|
26
|
+
if (typeof file === "object" && !React.isValidElement(file)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
// Handle string paths
|
|
30
|
+
if (typeof file === "string" && file.endsWith('.css')) {
|
|
31
|
+
// Handle different types of paths
|
|
32
|
+
let url = file;
|
|
33
|
+
if (file.startsWith('http') || file.startsWith('data:')) {
|
|
34
|
+
// Keep absolute URLs as is
|
|
35
|
+
url = file;
|
|
36
|
+
} else if (file.startsWith('/')) {
|
|
37
|
+
// Convert absolute paths to relative
|
|
38
|
+
url = base + file.slice(1);
|
|
39
|
+
} else if (!file.startsWith('./') && !file.startsWith('../')) {
|
|
40
|
+
// Add prefix to relative paths that don't start with ./ or ../
|
|
41
|
+
url = join(base, file);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return React.createElement("link", {
|
|
45
|
+
key: file,
|
|
46
|
+
rel: "stylesheet",
|
|
47
|
+
href: url,
|
|
48
|
+
precedence: "high",
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return null;
|
|
53
|
+
}).filter(Boolean);
|
|
54
|
+
|
|
55
|
+
return React.createElement(
|
|
56
|
+
React.Fragment,
|
|
57
|
+
null,
|
|
58
|
+
...elements,
|
|
59
|
+
children
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|