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
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
2
|
-
import { DEFAULT_CONFIG } from "../../config/defaults.js";
|
|
3
|
-
import { getPluginRoot } from "../../config/getPaths.js";
|
|
4
|
-
export function reactRscWorkerPlugin(options) {
|
|
5
|
-
return {
|
|
6
|
-
name: "vite:react-rsc-worker",
|
|
7
|
-
config(config) {
|
|
8
|
-
const root = config.root ?? process.cwd();
|
|
9
|
-
const pluginRoot = getPluginRoot();
|
|
10
|
-
const rscWorkerPath = typeof options.rscWorkerPath === "string"
|
|
11
|
-
? resolve(root, options.rscWorkerPath)
|
|
12
|
-
: resolve(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
|
|
13
|
-
const format = "esm";
|
|
14
|
-
// Single worker output for server build
|
|
15
|
-
const workerConfig = {
|
|
16
|
-
input: {
|
|
17
|
-
"rsc-worker": rscWorkerPath,
|
|
18
|
-
},
|
|
19
|
-
output: {
|
|
20
|
-
format,
|
|
21
|
-
dir: options.build?.server ?? "dist/server", // Output to server directory
|
|
22
|
-
entryFileNames: "[name].js",
|
|
23
|
-
preserveModules: true,
|
|
24
|
-
manualChunks: {
|
|
25
|
-
"rsc-worker": [rscWorkerPath],
|
|
26
|
-
},
|
|
27
|
-
resolve: {
|
|
28
|
-
conditions: ["react-server"],
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
build: {
|
|
34
|
-
rollupOptions: {
|
|
35
|
-
preserveEntrySignatures: "strict",
|
|
36
|
-
input: {
|
|
37
|
-
...workerConfig.input,
|
|
38
|
-
...(typeof config.build?.rollupOptions?.input === "object"
|
|
39
|
-
? config.build?.rollupOptions?.input
|
|
40
|
-
: {}),
|
|
41
|
-
},
|
|
42
|
-
external: [
|
|
43
|
-
"vite",
|
|
44
|
-
"rollup",
|
|
45
|
-
"react",
|
|
46
|
-
"react-dom",
|
|
47
|
-
"react-dom/server",
|
|
48
|
-
"react-server-dom-esm",
|
|
49
|
-
"react-server-dom-esm/client.node",
|
|
50
|
-
"react-server-dom-esm/server.node",
|
|
51
|
-
"react-server-dom-esm/node-loader",
|
|
52
|
-
"source-map",
|
|
53
|
-
"acorn-loose",
|
|
54
|
-
"webpack-sources",
|
|
55
|
-
"stream",
|
|
56
|
-
"util",
|
|
57
|
-
"crypto",
|
|
58
|
-
"async_hooks",
|
|
59
|
-
"fs",
|
|
60
|
-
"path",
|
|
61
|
-
"worker_threads",
|
|
62
|
-
// if we use node: paths in our code, it should always be catched by below rule.
|
|
63
|
-
/^node:.*/,
|
|
64
|
-
],
|
|
65
|
-
output: {
|
|
66
|
-
...workerConfig.output,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
manifest: true, // Ensure manifest is generated
|
|
70
|
-
minify: false,
|
|
71
|
-
sourcemap: true,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -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
|
-
}
|
package/plugin/components.tsx
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A component that emits <link> tags for CSS files during streaming.
|
|
5
|
-
* The high precedence ensures they bubble up to the document head.
|
|
6
|
-
*/
|
|
7
|
-
export function CssCollector({ url, moduleBasePath }: { url: string, moduleBasePath: string }) {
|
|
8
|
-
return createElement('link', {
|
|
9
|
-
key: url,
|
|
10
|
-
rel: 'stylesheet',
|
|
11
|
-
href: url,
|
|
12
|
-
precedence: 'high'
|
|
13
|
-
});
|
|
14
|
-
}
|
|
@@ -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;
|
package/plugin/getEnv.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import type { ConfigEnv, UserConfig } from "vite";
|
|
4
|
-
import { loadEnv } from "vite";
|
|
5
|
-
import { DEFAULT_CONFIG } from "./config/defaults.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get environment variables for Vite, sets defaults to ensure the server can start with BASE_URL and PUBLIC_URL
|
|
9
|
-
*
|
|
10
|
-
* @param config - Vite configuration object
|
|
11
|
-
* @param { isPreview: boolean } - Object containing a boolean indicating if the environment is for preview
|
|
12
|
-
* @returns An object containing the environment variables
|
|
13
|
-
*/
|
|
14
|
-
export function getEnv(config: UserConfig, configEnv: ConfigEnv) {
|
|
15
|
-
const isLocal =
|
|
16
|
-
config.mode === "development"
|
|
17
|
-
|
|
18
|
-
const envName = isLocal
|
|
19
|
-
? `${config.mode}.local`
|
|
20
|
-
: config.mode
|
|
21
|
-
? config.mode
|
|
22
|
-
: "production";
|
|
23
|
-
const environmentName = config.mode ?? envName ?? "production";
|
|
24
|
-
|
|
25
|
-
const env = loadEnv(
|
|
26
|
-
environmentName,
|
|
27
|
-
config.envDir ?? config.root ?? process.cwd(),
|
|
28
|
-
config.envPrefix ?? DEFAULT_CONFIG.ENV_PREFIX ?? "VITE_"
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// Get server config
|
|
32
|
-
const serverConfig = config.server || {};
|
|
33
|
-
const previewConfig = config.preview || {};
|
|
34
|
-
const host = configEnv.isPreview
|
|
35
|
-
? previewConfig.host ?? DEFAULT_CONFIG.PREVIEW_HOST
|
|
36
|
-
: serverConfig.host ?? DEFAULT_CONFIG.DEV_HOST;
|
|
37
|
-
let previewPort = previewConfig.port ?? DEFAULT_CONFIG.PREVIEW_PORT;
|
|
38
|
-
let devPort = serverConfig.port ?? DEFAULT_CONFIG.DEV_PORT;
|
|
39
|
-
|
|
40
|
-
let homepage = env["VITE_BASE_URL"]
|
|
41
|
-
if (configEnv.command === "build" && (!homepage || homepage === "")) {
|
|
42
|
-
try {
|
|
43
|
-
const packageJson = JSON.parse(
|
|
44
|
-
readFileSync(resolve(config.root ?? "", "package.json"), "utf-8")
|
|
45
|
-
);
|
|
46
|
-
homepage = packageJson.homepage ?? "";
|
|
47
|
-
if (!homepage || homepage === "") {
|
|
48
|
-
console.warn(
|
|
49
|
-
"[RSC] 🔧 For production builds, please set 'homepage' in package.json, or set VITE_BASE_URL in your environment"
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
} catch (e) {
|
|
53
|
-
console.error(e);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let baseUrl =
|
|
58
|
-
env["VITE_BASE_URL"] && env["VITE_PUBLIC_URL"] !== ""
|
|
59
|
-
? env["VITE_BASE_URL"]
|
|
60
|
-
: configEnv.isPreview
|
|
61
|
-
? `http://${host}:${previewPort}`
|
|
62
|
-
: configEnv.command === "serve"
|
|
63
|
-
? `http://${host}:${devPort}`
|
|
64
|
-
: homepage;
|
|
65
|
-
|
|
66
|
-
let publicUrl =
|
|
67
|
-
env["VITE_PUBLIC_URL"] && env["VITE_PUBLIC_URL"] !== ""
|
|
68
|
-
? env["VITE_PUBLIC_URL"]
|
|
69
|
-
: "";
|
|
70
|
-
|
|
71
|
-
// Determine port and host based on mode
|
|
72
|
-
const port = configEnv.isPreview
|
|
73
|
-
? previewConfig.port || DEFAULT_CONFIG.PREVIEW_PORT // Preview server
|
|
74
|
-
: serverConfig.port || DEFAULT_CONFIG.DEV_PORT; // Dev server
|
|
75
|
-
|
|
76
|
-
// Build base URL
|
|
77
|
-
if (configEnv.isPreview && `http://${host}:${port}` !== baseUrl) {
|
|
78
|
-
console.log(
|
|
79
|
-
`VITE_BASE_URL: \"${baseUrl}\" wasn't configured correctly for this server, overriding to: \"http://${host}:${port}\"`
|
|
80
|
-
);
|
|
81
|
-
baseUrl = `http://${host}:${port}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const envPrefix =
|
|
85
|
-
typeof config.envPrefix === "string"
|
|
86
|
-
? config.envPrefix
|
|
87
|
-
: Array.isArray(config.envPrefix)
|
|
88
|
-
? config.envPrefix[0]
|
|
89
|
-
: DEFAULT_CONFIG.ENV_PREFIX;
|
|
90
|
-
|
|
91
|
-
const nodeProcessEnv = {
|
|
92
|
-
NODE_ENV: configEnv.command === "build" ? "production" : "development",
|
|
93
|
-
};
|
|
94
|
-
const defineProcess = Object.entries(nodeProcessEnv)
|
|
95
|
-
.map(([key, value]) => {
|
|
96
|
-
switch (key) {
|
|
97
|
-
case "NODE_ENV":
|
|
98
|
-
const isDev =
|
|
99
|
-
value === ""
|
|
100
|
-
? configEnv.command === "build"
|
|
101
|
-
? false
|
|
102
|
-
: true
|
|
103
|
-
: value === "development";
|
|
104
|
-
return [`import.meta.env.DEV`, JSON.stringify(isDev)];
|
|
105
|
-
default:
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
.filter(Array.isArray);
|
|
110
|
-
|
|
111
|
-
const defineImportMeta = Object.entries(env).map(([key, value]) => [
|
|
112
|
-
`import.meta.env.${key}`,
|
|
113
|
-
key === "VITE_BASE_URL"
|
|
114
|
-
? value
|
|
115
|
-
? JSON.stringify(value)
|
|
116
|
-
: JSON.stringify(baseUrl)
|
|
117
|
-
: key === "VITE_PUBLIC_URL"
|
|
118
|
-
? value
|
|
119
|
-
? JSON.stringify(value)
|
|
120
|
-
: JSON.stringify(publicUrl)
|
|
121
|
-
: JSON.stringify(value),
|
|
122
|
-
]);
|
|
123
|
-
const define = Object.fromEntries([...defineProcess, ...defineImportMeta]);
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
baseUrl,
|
|
127
|
-
publicUrl,
|
|
128
|
-
port,
|
|
129
|
-
host,
|
|
130
|
-
envPrefix,
|
|
131
|
-
environmentName,
|
|
132
|
-
env,
|
|
133
|
-
define,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
@@ -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
|
-
|
package/plugin/module-graph.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { ModuleNode, ViteDevServer } from "vite";
|
|
2
|
-
|
|
3
|
-
export interface ModuleWithDeps {
|
|
4
|
-
id: string;
|
|
5
|
-
deps: Set<string>;
|
|
6
|
-
css: Set<string>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getModuleGraph(server: ViteDevServer) {
|
|
10
|
-
return {
|
|
11
|
-
async getModuleWithDeps(id: string): Promise<ModuleWithDeps> {
|
|
12
|
-
// Load module first to ensure it's in the module graph
|
|
13
|
-
await server.ssrLoadModule(id);
|
|
14
|
-
|
|
15
|
-
const resolvedId = await server.pluginContainer.resolveId(id, undefined, {
|
|
16
|
-
// Add ssr and react-server conditions
|
|
17
|
-
ssr: true,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
if (!resolvedId) throw new Error(`Module not found: ${id}`);
|
|
21
|
-
|
|
22
|
-
const moduleNode = server.moduleGraph.getModuleById(resolvedId.id);
|
|
23
|
-
if (!moduleNode) throw new Error(`Module node not found: ${id}`);
|
|
24
|
-
|
|
25
|
-
const deps = new Set<string>();
|
|
26
|
-
const css = new Set<string>();
|
|
27
|
-
|
|
28
|
-
// Recursively collect dependencies
|
|
29
|
-
const collectDeps = (node: ModuleNode) => {
|
|
30
|
-
// Track CSS imports
|
|
31
|
-
if (node.id?.endsWith(".css") && node.id) {
|
|
32
|
-
css.add(node.id);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Track all dependencies
|
|
36
|
-
for (const dep of node.importedModules) {
|
|
37
|
-
if (dep.id && !deps.has(dep.id)) {
|
|
38
|
-
deps.add(dep.id);
|
|
39
|
-
collectDeps(dep);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
collectDeps(moduleNode);
|
|
45
|
-
return { id: moduleNode.id ?? "", deps, css };
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|