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
package/dist/plugin/copy-dir.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { readdirSync, mkdirSync, statSync, copyFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
async function copyDir(src, dest, options) {
|
|
10
|
+
const entries = readdirSync(src);
|
|
11
|
+
mkdirSync(dest, { recursive: true });
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
const srcPath = join(src, entry);
|
|
14
|
+
const destPath = join(dest, entry);
|
|
15
|
+
const stat = statSync(srcPath);
|
|
16
|
+
if (stat.isDirectory()) {
|
|
17
|
+
await copyDir(srcPath, destPath);
|
|
18
|
+
} else {
|
|
19
|
+
copyFileSync(srcPath, destPath);
|
|
19
20
|
}
|
|
21
|
+
}
|
|
20
22
|
}
|
|
23
|
+
|
|
24
|
+
export { copyDir };
|
|
25
|
+
//# sourceMappingURL=copy-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-dir.js","sources":["../../plugin/copy-dir.ts"],"sourcesContent":["import { copyFileSync, mkdirSync, readdirSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nexport async function copyDir(src: string, dest: string, options?: { \n filter?: (file: string) => boolean \n}) {\n const entries = readdirSync(src);\n\n mkdirSync(dest, { recursive: true });\n\n for (const entry of entries) {\n const srcPath = join(src, entry);\n const destPath = join(dest, entry);\n\n const stat = statSync(srcPath);\n \n if (options?.filter && !options.filter(srcPath)) {\n continue;\n }\n\n if (stat.isDirectory()) {\n await copyDir(srcPath, destPath, options);\n } else {\n copyFileSync(srcPath, destPath);\n }\n }\n} "],"names":[],"mappings":";;;;;;;;AAGsB,eAAA,OAAA,CAAQ,GAAa,EAAA,IAAA,EAAc,OAEtD,EAAA;AACD,EAAM,MAAA,OAAA,GAAU,YAAY,GAAG,CAAA;AAE/B,EAAA,SAAA,CAAU,IAAM,EAAA,EAAE,SAAW,EAAA,IAAA,EAAM,CAAA;AAEnC,EAAA,KAAA,MAAW,SAAS,OAAS,EAAA;AAC3B,IAAM,MAAA,OAAA,GAAU,IAAK,CAAA,GAAA,EAAK,KAAK,CAAA;AAC/B,IAAM,MAAA,QAAA,GAAW,IAAK,CAAA,IAAA,EAAM,KAAK,CAAA;AAEjC,IAAM,MAAA,IAAA,GAAO,SAAS,OAAO,CAAA;AAM7B,IAAI,IAAA,IAAA,CAAK,aAAe,EAAA;AACtB,MAAM,MAAA,OAAA,CAAQ,OAAS,EAAA,QAAiB,CAAA;AAAA,KACnC,MAAA;AACL,MAAA,YAAA,CAAa,SAAS,QAAQ,CAAA;AAAA;AAChC;AAEJ;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { InlineCssCollectorProps } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A component that inlines pre-transformed CSS content.
|
|
5
|
+
* Expects cssFiles to be an array of CssContent objects with the content already loaded.
|
|
6
|
+
*/
|
|
7
|
+
export declare function InlineCssCollector({ children, cssFiles, moduleRootPath, }: InlineCssCollectorProps): React.FunctionComponentElement<{
|
|
8
|
+
children?: React.ReactNode | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=css-collector-inline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-collector-inline.d.ts","sourceRoot":"","sources":["../../plugin/css-collector-inline.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAG,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAU3D;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,QAAQ,EACR,cAAc,GACf,EAAE,uBAAuB;;GAuCzB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import React__default from 'react';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
|
|
10
|
+
function InlineCssCollector({
|
|
11
|
+
children,
|
|
12
|
+
cssFiles,
|
|
13
|
+
moduleRootPath
|
|
14
|
+
}) {
|
|
15
|
+
return React__default.createElement(
|
|
16
|
+
React__default.Fragment,
|
|
17
|
+
null,
|
|
18
|
+
cssFiles.map((file, index) => {
|
|
19
|
+
if (typeof file === "string") {
|
|
20
|
+
let filePath = file;
|
|
21
|
+
if (process.env["NODE_ENV"] === "development") {
|
|
22
|
+
return React__default.createElement("link", {
|
|
23
|
+
key: file,
|
|
24
|
+
rel: "stylesheet",
|
|
25
|
+
href: filePath
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return React__default.createElement(
|
|
29
|
+
"style",
|
|
30
|
+
{
|
|
31
|
+
key: file,
|
|
32
|
+
type: "text/css"
|
|
33
|
+
},
|
|
34
|
+
readFileSync(join(moduleRootPath, filePath), "utf-8")
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const { type, content, key, path } = file;
|
|
38
|
+
return React__default.createElement(
|
|
39
|
+
"style",
|
|
40
|
+
{
|
|
41
|
+
key: key ?? path ?? index,
|
|
42
|
+
type: type ?? "text/css",
|
|
43
|
+
...process.env["NODE_ENV"] === "development" && {
|
|
44
|
+
"data-vite-dev-id": join(moduleRootPath, path)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
content
|
|
48
|
+
);
|
|
49
|
+
}),
|
|
50
|
+
children
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { InlineCssCollector };
|
|
55
|
+
//# sourceMappingURL=css-collector-inline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-collector-inline.js","sources":["../../plugin/css-collector-inline.tsx"],"sourcesContent":["import React from \"react\";\nimport { join } from \"node:path\";\nimport type { InlineCssCollectorProps } from \"./types.js\";\nimport { readFileSync } from \"node:fs\";\n\ninterface CssContent {\n type?: string;\n content: string;\n key?: string;\n path: string;\n}\n\n/**\n * A component that inlines pre-transformed CSS content.\n * Expects cssFiles to be an array of CssContent objects with the content already loaded.\n */\nexport function InlineCssCollector({\n children,\n cssFiles,\n moduleRootPath,\n}: InlineCssCollectorProps) {\n return React.createElement(\n React.Fragment,\n null,\n cssFiles.map((file, index) => {\n if (typeof file === \"string\") {\n let filePath = file as string;\n if(process.env[\"NODE_ENV\"] === \"development\") {\n return React.createElement(\"link\", {\n key: file,\n rel: \"stylesheet\",\n href: filePath,\n });\n }\n return React.createElement(\n \"style\",\n {\n key: file,\n type: \"text/css\",\n },\n readFileSync(join(moduleRootPath, filePath), \"utf-8\")\n );\n }\n\n const { type, content, key, path } = file as CssContent;\n return React.createElement(\n \"style\",\n {\n key: key ?? path ?? index,\n type: type ?? \"text/css\",\n ...(process.env[\"NODE_ENV\"] === \"development\" && {\n \"data-vite-dev-id\": join(moduleRootPath, path),\n }),\n },\n content\n );\n }),\n children\n );\n}\n"],"names":["React"],"mappings":";;;;;;;;;AAgBO,SAAS,kBAAmB,CAAA;AAAA,EACjC,QAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAA4B,EAAA;AAC1B,EAAA,OAAOA,cAAM,CAAA,aAAA;AAAA,IACXA,cAAM,CAAA,QAAA;AAAA,IACN,IAAA;AAAA,IACA,QAAS,CAAA,GAAA,CAAI,CAAC,IAAA,EAAM,KAAU,KAAA;AAC5B,MAAI,IAAA,OAAO,SAAS,QAAU,EAAA;AAC5B,QAAA,IAAI,QAAW,GAAA,IAAA;AACf,QAAA,IAAG,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,KAAM,aAAe,EAAA;AAC5C,UAAO,OAAAA,cAAA,CAAM,cAAc,MAAQ,EAAA;AAAA,YACjC,GAAK,EAAA,IAAA;AAAA,YACL,GAAK,EAAA,YAAA;AAAA,YACL,IAAM,EAAA;AAAA,WACP,CAAA;AAAA;AAEH,QAAA,OAAOA,cAAM,CAAA,aAAA;AAAA,UACX,OAAA;AAAA,UACA;AAAA,YACE,GAAK,EAAA,IAAA;AAAA,YACL,IAAM,EAAA;AAAA,WACR;AAAA,UACA,YAAa,CAAA,IAAA,CAAK,cAAgB,EAAA,QAAQ,GAAG,OAAO;AAAA,SACtD;AAAA;AAGF,MAAA,MAAM,EAAE,IAAA,EAAM,OAAS,EAAA,GAAA,EAAK,MAAS,GAAA,IAAA;AACrC,MAAA,OAAOA,cAAM,CAAA,aAAA;AAAA,QACX,OAAA;AAAA,QACA;AAAA,UACE,GAAA,EAAK,OAAO,IAAQ,IAAA,KAAA;AAAA,UACpB,MAAM,IAAQ,IAAA,UAAA;AAAA,UACd,GAAI,OAAA,CAAQ,GAAI,CAAA,UAAU,MAAM,aAAiB,IAAA;AAAA,YAC/C,kBAAA,EAAoB,IAAK,CAAA,cAAA,EAAgB,IAAI;AAAA;AAC/C,SACF;AAAA,QACA;AAAA,OACF;AAAA,KACD,CAAA;AAAA,IACD;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A component that emits <link> tags for CSS files during streaming.
|
|
4
|
+
* The high precedence ensures they bubble up to the document head.
|
|
5
|
+
*/
|
|
6
|
+
export declare function CssCollector({ children, cssFiles, moduleBaseURL, route, }: {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
cssFiles: string[];
|
|
9
|
+
moduleBaseURL?: string;
|
|
10
|
+
route?: string;
|
|
11
|
+
}): React.FunctionComponentElement<{
|
|
12
|
+
children?: React.ReactNode | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=css-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-collector.d.ts","sourceRoot":"","sources":["../../plugin/css-collector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,KAAW,GACZ,EAAE;IACD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;;GA2CA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import React__default from 'react';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
function CssCollector({
|
|
10
|
+
children,
|
|
11
|
+
cssFiles,
|
|
12
|
+
moduleBaseURL,
|
|
13
|
+
route = "/"
|
|
14
|
+
}) {
|
|
15
|
+
const depth = route.split("/").filter(Boolean).length;
|
|
16
|
+
const prefix = depth > 0 ? "../".repeat(depth) : "./";
|
|
17
|
+
const base = typeof moduleBaseURL === "string" && moduleBaseURL !== "" ? moduleBaseURL : prefix;
|
|
18
|
+
const elements = cssFiles.map((file) => {
|
|
19
|
+
if (typeof file === "object" && !React__default.isValidElement(file)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (typeof file === "string" && file.endsWith(".css")) {
|
|
23
|
+
let url = file;
|
|
24
|
+
if (file.startsWith("http") || file.startsWith("data:")) {
|
|
25
|
+
url = file;
|
|
26
|
+
} else if (file.startsWith("/")) {
|
|
27
|
+
url = base + file.slice(1);
|
|
28
|
+
} else if (!file.startsWith("./") && !file.startsWith("../")) {
|
|
29
|
+
url = join(base, file);
|
|
30
|
+
}
|
|
31
|
+
return React__default.createElement("link", {
|
|
32
|
+
key: file,
|
|
33
|
+
rel: "stylesheet",
|
|
34
|
+
href: url,
|
|
35
|
+
precedence: "high"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}).filter(Boolean);
|
|
40
|
+
return React__default.createElement(
|
|
41
|
+
React__default.Fragment,
|
|
42
|
+
null,
|
|
43
|
+
...elements,
|
|
44
|
+
children
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { CssCollector };
|
|
49
|
+
//# sourceMappingURL=css-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-collector.js","sources":["../../plugin/css-collector.tsx"],"sourcesContent":["import React from \"react\";\nimport { join } from \"node:path\";\n\n/**\n * A component that emits <link> tags for CSS files during streaming.\n * The high precedence ensures they bubble up to the document head.\n */\nexport function CssCollector({\n children,\n cssFiles,\n moduleBaseURL,\n route = \"/\",\n}: {\n children?: React.ReactNode;\n cssFiles: string[];\n moduleBaseURL?: string;\n route?: string;\n}) {\n // Calculate depth and prefix based on route\n const depth = route.split('/').filter(Boolean).length;\n const prefix = depth > 0 ? '../'.repeat(depth) : './';\n const base = typeof moduleBaseURL === 'string' && moduleBaseURL !== '' ? moduleBaseURL : prefix;\n\n const elements = cssFiles.map((file) => {\n // Handle pre-processed CSS content - skip in link mode\n if (typeof file === \"object\" && !React.isValidElement(file)) {\n return null;\n }\n // Handle string paths\n if (typeof file === \"string\" && file.endsWith('.css')) {\n // Handle different types of paths\n let url = file;\n if (file.startsWith('http') || file.startsWith('data:')) {\n // Keep absolute URLs as is\n url = file;\n } else if (file.startsWith('/')) {\n // Convert absolute paths to relative\n url = base + file.slice(1);\n } else if (!file.startsWith('./') && !file.startsWith('../')) {\n // Add prefix to relative paths that don't start with ./ or ../\n url = join(base, file);\n }\n \n return React.createElement(\"link\", {\n key: file,\n rel: \"stylesheet\",\n href: url,\n precedence: \"high\",\n });\n }\n\n return null;\n }).filter(Boolean);\n\n return React.createElement(\n React.Fragment,\n null,\n ...elements,\n children\n );\n}\n\n"],"names":["React"],"mappings":";;;;;;;;AAOO,SAAS,YAAa,CAAA;AAAA,EAC3B,QAAA;AAAA,EACA,QAAA;AAAA,EACA,aAAA;AAAA,EACA,KAAQ,GAAA;AACV,CAKG,EAAA;AAED,EAAA,MAAM,QAAQ,KAAM,CAAA,KAAA,CAAM,GAAG,CAAE,CAAA,MAAA,CAAO,OAAO,CAAE,CAAA,MAAA;AAC/C,EAA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A,aAAA;AAAA,IACXA,cAAM,CAAA,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,QAAA;AAAA,IACH;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PipeableStream } from "react-dom/server";
|
|
2
|
+
import type { CreateHandlerOptions } from "../types.js";
|
|
3
|
+
type CreateHandlerResult = {
|
|
4
|
+
type: "success";
|
|
5
|
+
controller: AbortController;
|
|
6
|
+
stream: PipeableStream;
|
|
7
|
+
assets: any;
|
|
8
|
+
route: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: "error";
|
|
11
|
+
error: Error;
|
|
12
|
+
} | {
|
|
13
|
+
type: "skip";
|
|
14
|
+
};
|
|
15
|
+
export declare function createHandler<T>({ getCss, root, cssFiles, cssModules, onCssFile, logger, loader, Html, CssCollector, pagePath, propsPath, pageExportName, propsExportName, inlineCss, moduleBase, preserveModulesRoot: _preserveModulesRoot, moduleBasePath, moduleRootPath, moduleBaseURL, route, pipableStreamOptions, }: CreateHandlerOptions<T>): Promise<CreateHandlerResult>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=createHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHandler.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,KAAK,EAAE,oBAAoB,EAAc,MAAM,aAAa,CAAC;AAEpE,KAAK,mBAAmB,GACpB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,eAAe,CAAC;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE,GAAG,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAOrB,wBAAsB,aAAa,CAAC,CAAC,EAAE,EACrC,MAAM,EACN,IAAI,EACJ,QAAa,EACb,UAAmD,EACnD,SAAS,EACT,MAAM,EACN,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,cAAc,EACd,eAAe,EACf,SAAS,EACT,UAAU,EACV,mBAAmB,EAAE,oBAAoB,EACzC,cAAc,EACd,cAAc,EACd,aAAa,EACb,KAAK,EACL,oBAAoB,GACrB,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA2FxD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import { resolvePage } from '../resolvePage.js';
|
|
7
|
+
import { resolveProps } from '../resolveProps.js';
|
|
8
|
+
import { createRscStream } from './createRscStream.js';
|
|
9
|
+
|
|
10
|
+
async function createHandler({
|
|
11
|
+
getCss,
|
|
12
|
+
root,
|
|
13
|
+
cssFiles = [],
|
|
14
|
+
cssModules = /* @__PURE__ */ new Map(),
|
|
15
|
+
onCssFile,
|
|
16
|
+
logger,
|
|
17
|
+
loader,
|
|
18
|
+
Html,
|
|
19
|
+
CssCollector,
|
|
20
|
+
pagePath,
|
|
21
|
+
propsPath,
|
|
22
|
+
pageExportName,
|
|
23
|
+
propsExportName,
|
|
24
|
+
inlineCss,
|
|
25
|
+
moduleBase,
|
|
26
|
+
preserveModulesRoot: _preserveModulesRoot,
|
|
27
|
+
moduleBasePath,
|
|
28
|
+
moduleRootPath,
|
|
29
|
+
moduleBaseURL,
|
|
30
|
+
route,
|
|
31
|
+
pipableStreamOptions
|
|
32
|
+
}) {
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const loadWithCss = async (id) => {
|
|
35
|
+
try {
|
|
36
|
+
const mod = await loader(id);
|
|
37
|
+
const pageCss = await Promise.resolve(getCss(id));
|
|
38
|
+
Array.from(pageCss.entries()).forEach(([css, linkOrContent]) => {
|
|
39
|
+
cssModules.set(css, linkOrContent);
|
|
40
|
+
if (typeof onCssFile === "function") {
|
|
41
|
+
onCssFile(css, id);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return mod;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (e.message?.includes("module runner has been closed")) {
|
|
47
|
+
return { type: "skip" };
|
|
48
|
+
} else {
|
|
49
|
+
return { type: "error", error: e };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const PropsModule = await resolveProps({
|
|
54
|
+
propsModule: propsPath ? await loadWithCss(propsPath) : { [propsExportName]: (url2) => ({ url: url2 }) },
|
|
55
|
+
path: String(propsPath),
|
|
56
|
+
exportName: propsExportName,
|
|
57
|
+
url: route
|
|
58
|
+
});
|
|
59
|
+
if (PropsModule.type !== "success") {
|
|
60
|
+
return PropsModule;
|
|
61
|
+
}
|
|
62
|
+
const PageModule = await resolvePage({
|
|
63
|
+
pageModule: pagePath ? await loadWithCss(pagePath) : { [pageExportName]: () => null },
|
|
64
|
+
path: String(pagePath),
|
|
65
|
+
exportName: pageExportName,
|
|
66
|
+
url: route
|
|
67
|
+
});
|
|
68
|
+
if (PageModule.type !== "success") {
|
|
69
|
+
return PageModule;
|
|
70
|
+
}
|
|
71
|
+
if (cssFiles) {
|
|
72
|
+
cssFiles.forEach((css) => cssModules.set(typeof css === "string" ? css : css.path, css));
|
|
73
|
+
cssFiles = Array.from(cssModules.values());
|
|
74
|
+
}
|
|
75
|
+
const url = typeof moduleBaseURL === "string" && moduleBaseURL !== "" ? new URL(route, moduleBaseURL).href : route;
|
|
76
|
+
const stream = createRscStream({
|
|
77
|
+
Html,
|
|
78
|
+
CssCollector,
|
|
79
|
+
Page: PageModule[pageExportName],
|
|
80
|
+
props: PropsModule[propsExportName],
|
|
81
|
+
moduleRootPath,
|
|
82
|
+
moduleBasePath,
|
|
83
|
+
moduleBaseURL,
|
|
84
|
+
logger,
|
|
85
|
+
cssFiles: Array.from(cssModules.values()),
|
|
86
|
+
route,
|
|
87
|
+
url,
|
|
88
|
+
pipableStreamOptions,
|
|
89
|
+
htmlProps: {},
|
|
90
|
+
root,
|
|
91
|
+
loader,
|
|
92
|
+
inlineCss
|
|
93
|
+
});
|
|
94
|
+
if (!stream) {
|
|
95
|
+
return { type: "skip" };
|
|
96
|
+
}
|
|
97
|
+
const assets = {
|
|
98
|
+
css: cssFiles,
|
|
99
|
+
bootstrapModules: pipableStreamOptions?.bootstrapModules ?? []
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
type: "success",
|
|
103
|
+
controller,
|
|
104
|
+
stream,
|
|
105
|
+
assets,
|
|
106
|
+
route
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { createHandler };
|
|
111
|
+
//# sourceMappingURL=createHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHandler.js","sources":["../../../plugin/helpers/createHandler.ts"],"sourcesContent":["import type { PipeableStream } from \"react-dom/server\";\nimport { resolvePage } from \"../resolvePage.js\";\nimport { resolveProps } from \"../resolveProps.js\";\nimport type { CreateHandlerOptions, CssContent } from \"../types.js\";\nimport { createRscStream } from \"./createRscStream.js\";\ntype CreateHandlerResult =\n | {\n type: \"success\";\n controller: AbortController;\n stream: PipeableStream;\n assets: any;\n route: string;\n }\n | { type: \"error\"; error: Error }\n | { type: \"skip\" };\n\ninterface HandlerAssets {\n css: (string | CssContent)[];\n bootstrapModules: string[];\n}\n\nexport async function createHandler<T>({\n getCss,\n root,\n cssFiles = [],\n cssModules = new Map<string, string | CssContent>(),\n onCssFile,\n logger,\n loader,\n Html,\n CssCollector,\n pagePath,\n propsPath,\n pageExportName,\n propsExportName,\n inlineCss,\n moduleBase,\n preserveModulesRoot: _preserveModulesRoot,\n moduleBasePath,\n moduleRootPath,\n moduleBaseURL,\n route,\n pipableStreamOptions,\n}: CreateHandlerOptions<T>): Promise<CreateHandlerResult> {\n const controller = new AbortController();\n\n const loadWithCss = async (id: string) => {\n try {\n const mod = await loader(id);\n const pageCss = await Promise.resolve(getCss(id));\n Array.from(pageCss.entries()).forEach(([css, linkOrContent]) => {\n cssModules.set(css, linkOrContent);\n // Notify about new CSS file if callback exists\n if (typeof onCssFile === \"function\") {\n onCssFile(css, id);\n }\n });\n return mod as Record<string, any>;\n } catch (e: any) {\n if (e.message?.includes(\"module runner has been closed\")) {\n return { type: \"skip\" } as Record<string, any>;\n } else {\n return { type: \"error\", error: e } as Record<string, any>;\n }\n }\n };\n\n const PropsModule = await resolveProps({\n propsModule: propsPath\n ? await loadWithCss(propsPath)\n : { [propsExportName]: (url: string) => ({url}) },\n path: String(propsPath),\n exportName: propsExportName,\n url: route,\n });\n if (PropsModule.type !== \"success\") {\n return PropsModule;\n }\n const PageModule = await resolvePage({\n pageModule: pagePath\n ? await loadWithCss(pagePath)\n : { [pageExportName]: () => null },\n path: String(pagePath),\n exportName: pageExportName,\n url: route,\n });\n if (PageModule.type !== \"success\") {\n return PageModule;\n }\n\n // Add any additional CSS files\n if (cssFiles) {\n cssFiles.forEach((css) => cssModules.set(typeof css === \"string\" ? css : css.path, css));\n cssFiles = Array.from(cssModules.values());\n }\n const url =\n typeof moduleBaseURL === \"string\" && moduleBaseURL !== \"\"\n ? new URL(route, moduleBaseURL).href\n : route;\n const stream = createRscStream({\n Html: Html,\n CssCollector: CssCollector,\n Page: PageModule[pageExportName as keyof typeof PageModule],\n props: PropsModule[propsExportName as keyof typeof PropsModule],\n moduleBase: moduleBase,\n moduleRootPath: moduleRootPath,\n moduleBasePath: moduleBasePath,\n moduleBaseURL: moduleBaseURL,\n logger: logger,\n cssFiles: Array.from(cssModules.values()),\n route,\n url,\n pipableStreamOptions: pipableStreamOptions,\n htmlProps: {},\n root: root,\n loader: loader,\n inlineCss: inlineCss,\n });\n\n if (!stream) {\n return { type: \"skip\" as const };\n }\n\n const assets: HandlerAssets = {\n css: cssFiles,\n bootstrapModules: pipableStreamOptions?.bootstrapModules ?? [],\n };\n return {\n type: \"success\",\n controller,\n stream,\n assets,\n route: route,\n };\n}\n"],"names":["url"],"mappings":";;;;;;;;;AAqBA,eAAsB,aAAiB,CAAA;AAAA,EACrC,MAAA;AAAA,EACA,IAAA;AAAA,EACA,WAAW,EAAC;AAAA,EACZ,UAAA,uBAAiB,GAAiC,EAAA;AAAA,EAClD,SAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,mBAAqB,EAAA,oBAAA;AAAA,EACrB,cAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF,CAA0D,EAAA;AACxD,EAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AAEvC,EAAM,MAAA,WAAA,GAAc,OAAO,EAAe,KAAA;AACxC,IAAI,IAAA;AACF,MAAM,MAAA,GAAA,GAAM,MAAM,MAAA,CAAO,EAAE,CAAA;AAC3B,MAAA,MAAM,UAAU,MAAM,OAAA,CAAQ,OAAQ,CAAA,MAAA,CAAO,EAAE,CAAC,CAAA;AAChD,MAAM,KAAA,CAAA,IAAA,CAAK,OAAQ,CAAA,OAAA,EAAS,CAAA,CAAE,QAAQ,CAAC,CAAC,GAAK,EAAA,aAAa,CAAM,KAAA;AAC9D,QAAW,UAAA,CAAA,GAAA,CAAI,KAAK,aAAa,CAAA;AAEjC,QAAI,IAAA,OAAO,cAAc,UAAY,EAAA;AACnC,UAAA,SAAA,CAAU,KAAK,EAAE,CAAA;AAAA;AACnB,OACD,CAAA;AACD,MAAO,OAAA,GAAA;AAAA,aACA,CA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,CAAA,MAAA,EAAQ,CAAA;AAAA;AAE3C,EAAM,MAAA,GAAA,GACJ,OAAO,aAAA,KAAkB,QAAY,IAAA,aAAA,KAAkB,EACnD,GAAA,IAAI,GAAI,CAAA,KAAA,EAAO,aAAa,CAAA,CAAE,IAC9B,GAAA,KAAA;AACN,EAAA,MAAM,SAAS,eAAgB,CAAA;AAAA,IAC7B,IAAA;AAAA,IACA,YAAA;AAAA,IACA,IAAA,EAAM,WAAW,cAAyC,CAAA;AAAA,IAC1D,KAAA,EAAO,YAAY,eAA2C,CAAA;AAAA,IAE9D,cAAA;AAAA,IACA,cAAA;AAAA,IACA,aAAA;AAAA,IACA,MAAA;AAAA,IACA,QAAU,EAAA,KAAA,CAAM,IAAK,CAAA,UAAA,CAAW,QAAQ,CAAA;AAAA,IACxC,KAAA;AAAA,IACA,GAAA;AAAA,IACA,oBAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,EAAE,MAAM,MAAgB,EAAA;AAAA;AAGjC,EAAA,MAAM,MAAwB,GAAA;AAAA,IAC5B,GAAK,EAAA,QAAA;AAAA,IACL,gBAAA,EAAkB,oBAAsB,EAAA,gBAAA,IAAoB;AAAC,GAC/D;AACA,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,UAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { PipeableStreamOptions } from "../worker/types.js";
|
|
3
|
+
import type { Logger } from "vite";
|
|
4
|
+
import type { CreateHandlerOptions, CssCollectorProps, CssContent, InlineCssCollectorProps } from "../types.js";
|
|
5
|
+
export declare function createRscStream<InlineCSS extends boolean = true>({ Html, Page, props, loader, moduleRootPath, moduleBasePath, moduleBaseURL, logger, cssFiles, route, url, pipableStreamOptions, htmlProps, inlineCss, CssCollector, root, }: {
|
|
6
|
+
Html: CreateHandlerOptions["Html"];
|
|
7
|
+
Page: React.ComponentType<any>;
|
|
8
|
+
loader: (id: string) => Promise<any>;
|
|
9
|
+
props: any;
|
|
10
|
+
moduleBase: string;
|
|
11
|
+
moduleRootPath: string;
|
|
12
|
+
moduleBasePath: string;
|
|
13
|
+
moduleBaseURL: string;
|
|
14
|
+
logger: Logger;
|
|
15
|
+
route: string;
|
|
16
|
+
url: string;
|
|
17
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
18
|
+
htmlProps?: any;
|
|
19
|
+
root: string;
|
|
20
|
+
inlineCss?: InlineCSS;
|
|
21
|
+
cssFiles?: (string | CssContent)[];
|
|
22
|
+
} & (InlineCSS extends true ? {
|
|
23
|
+
CssCollector: React.FC<InlineCssCollectorProps>;
|
|
24
|
+
} : {
|
|
25
|
+
CssCollector: React.FC<CssCollectorProps>;
|
|
26
|
+
})): any;
|
|
27
|
+
//# sourceMappingURL=createRscStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRscStream.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/createRscStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB,wBAAgB,eAAe,CAAC,SAAS,SAAS,OAAO,GAAG,IAAI,EAAE,EAChE,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,MAAkD,EAClD,cAAc,EACd,cAAc,EACd,aAAa,EACb,MAAM,EACN,QAAa,EACb,KAAK,EACL,GAAG,EACH,oBAAoB,EACpB,SAAS,EACT,SAA6B,EAC7B,YAAY,EACZ,IAAI,GACL,EAAE;IACD,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACrC,KAAK,EAAE,GAAG,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,oBAAoB,CAAC,EAAE,qBAAqB,CAAC;IAC7C,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC;CACpC,GAAG,CAAC,SAAS,SAAS,IAAI,GACvB;IACE,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC;CACjD,GACD;IACE,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;CAC3C,CAAC,OAwDL"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { renderToPipeableStream } from 'react-server-dom-esm/server.node';
|
|
8
|
+
|
|
9
|
+
function createRscStream({
|
|
10
|
+
Html,
|
|
11
|
+
Page,
|
|
12
|
+
props,
|
|
13
|
+
loader = (id) => import(id).then((m) => m.default),
|
|
14
|
+
moduleRootPath,
|
|
15
|
+
moduleBasePath,
|
|
16
|
+
moduleBaseURL,
|
|
17
|
+
logger,
|
|
18
|
+
cssFiles = [],
|
|
19
|
+
route,
|
|
20
|
+
url,
|
|
21
|
+
pipableStreamOptions,
|
|
22
|
+
htmlProps,
|
|
23
|
+
inlineCss = true,
|
|
24
|
+
CssCollector,
|
|
25
|
+
root
|
|
26
|
+
}) {
|
|
27
|
+
const htmlIsFragment = Html == React.Fragment;
|
|
28
|
+
if (!htmlIsFragment) {
|
|
29
|
+
if (!htmlProps) {
|
|
30
|
+
htmlProps = {};
|
|
31
|
+
}
|
|
32
|
+
if (!("moduleBaseURL" in htmlProps)) {
|
|
33
|
+
htmlProps["moduleBaseURL"] = moduleBaseURL;
|
|
34
|
+
}
|
|
35
|
+
if (!("moduleBasePath" in htmlProps)) {
|
|
36
|
+
htmlProps["moduleBasePath"] = moduleBasePath;
|
|
37
|
+
}
|
|
38
|
+
if (!("moduleRootPath" in htmlProps)) {
|
|
39
|
+
htmlProps["moduleRootPath"] = moduleRootPath;
|
|
40
|
+
}
|
|
41
|
+
if (!("url" in htmlProps)) {
|
|
42
|
+
htmlProps["url"] = url;
|
|
43
|
+
}
|
|
44
|
+
if (!("route" in htmlProps)) {
|
|
45
|
+
htmlProps["route"] = route;
|
|
46
|
+
}
|
|
47
|
+
if (!("pageProps" in htmlProps)) {
|
|
48
|
+
htmlProps["pageProps"] = props;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const withCss = React.createElement(
|
|
52
|
+
CssCollector,
|
|
53
|
+
inlineCss === true ? {
|
|
54
|
+
cssFiles,
|
|
55
|
+
route,
|
|
56
|
+
moduleBaseURL,
|
|
57
|
+
moduleBasePath,
|
|
58
|
+
moduleRootPath,
|
|
59
|
+
root,
|
|
60
|
+
loader
|
|
61
|
+
} : { cssFiles, route, moduleBaseURL },
|
|
62
|
+
React.createElement(Page, props)
|
|
63
|
+
);
|
|
64
|
+
const content = htmlIsFragment ? withCss : React.createElement(Html, htmlProps, withCss);
|
|
65
|
+
try {
|
|
66
|
+
return renderToPipeableStream(
|
|
67
|
+
content,
|
|
68
|
+
moduleBasePath,
|
|
69
|
+
pipableStreamOptions
|
|
70
|
+
);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
logger.error(`Failed to create stream for ${route}.`, {
|
|
73
|
+
error
|
|
74
|
+
});
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { createRscStream };
|
|
80
|
+
//# sourceMappingURL=createRscStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRscStream.js","sources":["../../../plugin/helpers/createRscStream.ts"],"sourcesContent":["import * as React from \"react\";\n// @ts-ignore\nimport { renderToPipeableStream } from \"react-server-dom-esm/server.node\";\nimport type { PipeableStreamOptions } from \"../worker/types.js\";\nimport type { Logger } from \"vite\";\nimport type {\n CreateHandlerOptions,\n CssCollectorProps,\n CssContent,\n InlineCssCollectorProps,\n} from \"../types.js\";\n\nexport function createRscStream<InlineCSS extends boolean = true>({\n Html,\n Page,\n props,\n loader = (id) => import(id).then((m) => m.default),\n moduleRootPath,\n moduleBasePath,\n moduleBaseURL,\n logger,\n cssFiles = [],\n route,\n url,\n pipableStreamOptions,\n htmlProps,\n inlineCss = true as InlineCSS,\n CssCollector,\n root,\n}: {\n Html: CreateHandlerOptions[\"Html\"];\n Page: React.ComponentType<any>;\n loader: (id: string) => Promise<any>;\n props: any;\n moduleBase: string;\n moduleRootPath: string;\n moduleBasePath: string;\n moduleBaseURL: string;\n logger: Logger;\n route: string;\n url: string;\n pipableStreamOptions?: PipeableStreamOptions;\n htmlProps?: any;\n root: string;\n inlineCss?: InlineCSS;\n cssFiles?: (string | CssContent)[];\n} & (InlineCSS extends true\n ? {\n CssCollector: React.FC<InlineCssCollectorProps>;\n }\n : {\n CssCollector: React.FC<CssCollectorProps>;\n })) {\n const htmlIsFragment = Html == React.Fragment;\n if (!htmlIsFragment) {\n if (!htmlProps) {\n htmlProps = {};\n }\n if (!(\"moduleBaseURL\" in htmlProps)) {\n htmlProps[\"moduleBaseURL\"] = moduleBaseURL;\n }\n if (!(\"moduleBasePath\" in htmlProps)) {\n htmlProps[\"moduleBasePath\"] = moduleBasePath;\n }\n if (!(\"moduleRootPath\" in htmlProps)) {\n htmlProps[\"moduleRootPath\"] = moduleRootPath;\n }\n if (!(\"url\" in htmlProps)) {\n htmlProps[\"url\"] = url;\n }\n if (!(\"route\" in htmlProps)) {\n htmlProps[\"route\"] = route;\n }\n if (!(\"pageProps\" in htmlProps)) {\n htmlProps[\"pageProps\"] = props;\n }\n }\n const withCss = React.createElement(\n CssCollector as any,\n (inlineCss === true\n ? {\n cssFiles: cssFiles,\n route,\n moduleBaseURL,\n moduleBasePath,\n moduleRootPath,\n root,\n loader,\n }\n : { cssFiles: cssFiles, route, moduleBaseURL }) as any,\n React.createElement(Page, props)\n );\n // Otherwise wrap with Html component\n const content = htmlIsFragment\n ? withCss\n : React.createElement(Html, htmlProps, withCss);\n try {\n return renderToPipeableStream(\n content,\n moduleBasePath,\n pipableStreamOptions\n );\n } catch (error) {\n logger.error(`Failed to create stream for ${route}.`, {\n error: error as Error,\n });\n return null;\n }\n}\n"],"names":[],"mappings":";;;;;;;;AAYO,SAAS,eAAkD,CAAA;AAAA,EAChE,IAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA,GAAS,CAAC,EAAO,KAAA,OAAO,IAAI,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,OAAO,CAAA;AAAA,EACjD,cAAA;AAAA,EACA,cAAA;AAAA,EACA,aAAA;AAAA,EACA,MAAA;AAAA,EACA,WAAW,EAAC;AAAA,EACZ,KAAA;AAAA,EACA,GAAA;AAAA,EACA,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAY,GAAA,IAAA;AAAA,EACZ,YAAA;AAAA,EACA;AACF,CAuBQ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A;AAChD,EAAI,IAAA;AACF,IAAO,OAAA,sBAAA;AAAA,MACL,OAAA;AAAA,MACA,cAAA;AAAA,MACA;AAAA,KACF;AAAA,WACO,KAAO,EAAA;AACd,IAAO,MAAA,CAAA,KAAA,CAAM,CAA+B,4BAAA,EAAA,KAAK,CAAK,CAAA,CAAA,EAAA;AAAA,MACpD;AAAA,KACD,CAAA;AACD,IAAO,OAAA,IAAA;AAAA;AAEX;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleManifest.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/getBundleManifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAEd,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"getBundleManifest.d.ts","sourceRoot":"","sources":["../../../plugin/helpers/getBundleManifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EAEd,MAAM,QAAQ,CAAC;AAIhB,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,aAAa,EACb,MAAM,EACN,UAAU,EACV,mBAAmB,GACpB,EAAE;IACD,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAsFtC"}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* MIT License
|
|
5
5
|
*/
|
|
6
6
|
import { createInputNormalizer } from './inputNormalizer.js';
|
|
7
|
-
import 'path';
|
|
8
7
|
import { DEFAULT_CONFIG } from '../config/defaults.js';
|
|
9
8
|
|
|
10
9
|
function getBundleManifest({
|
|
@@ -36,7 +35,7 @@ function getBundleManifest({
|
|
|
36
35
|
}
|
|
37
36
|
];
|
|
38
37
|
}
|
|
39
|
-
|
|
38
|
+
let [normalizedId, sourcePath] = normalizer(moduleId);
|
|
40
39
|
let finalFileName = fileName;
|
|
41
40
|
if (moduleId.includes("?")) {
|
|
42
41
|
const [basePath, query] = moduleId.split("?");
|
|
@@ -48,12 +47,21 @@ function getBundleManifest({
|
|
|
48
47
|
}
|
|
49
48
|
finalFileName = virtualModules.get(virtualKey);
|
|
50
49
|
}
|
|
50
|
+
if (normalizedId.startsWith("\0")) {
|
|
51
|
+
normalizedId = normalizedId.slice(1);
|
|
52
|
+
}
|
|
53
|
+
if (sourcePath.startsWith("/")) {
|
|
54
|
+
sourcePath = sourcePath.slice(1);
|
|
55
|
+
}
|
|
56
|
+
if (moduleBase && preserveModulesRoot && normalizedId?.startsWith(moduleBase + "/")) {
|
|
57
|
+
normalizedId = normalizedId.slice(moduleBase.length + 1);
|
|
58
|
+
}
|
|
51
59
|
const bundleManifestEntry = [
|
|
52
60
|
sourcePath,
|
|
53
61
|
{
|
|
54
62
|
file: finalFileName,
|
|
55
|
-
name: normalizedId
|
|
56
|
-
src: sourcePath
|
|
63
|
+
name: normalizedId,
|
|
64
|
+
src: sourcePath,
|
|
57
65
|
isEntry: chunk.isEntry,
|
|
58
66
|
...chunk.imports?.length > 0 ? { imports: chunk.imports } : {},
|
|
59
67
|
...chunk.dynamicImports?.length > 0 ? { dynamicImports: chunk.dynamicImports } : {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleManifest.js","sources":["../../../plugin/helpers/getBundleManifest.ts"],"sourcesContent":["import type {\n OutputBundle,\n PluginContext,\n OutputChunk,\n} from \"rollup\";\nimport { createInputNormalizer } from \"./inputNormalizer.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"getBundleManifest.js","sources":["../../../plugin/helpers/getBundleManifest.ts"],"sourcesContent":["import type {\n OutputBundle,\n PluginContext,\n OutputChunk,\n} from \"rollup\";\nimport { createInputNormalizer } from \"./inputNormalizer.js\";\nimport { DEFAULT_CONFIG } from \"../config/index.js\";\n\ninterface BundleManifestEntry {\n file: string;\n name: string;\n src?: string;\n isEntry?: boolean;\n imports?: string[];\n dynamicImports?: string[];\n css?: string[];\n}\n\n/**\n * Get the bundle manifest from the plugin context. Will only work during production build\n * @param pluginContext - The plugin context\n * @param bundle - The bundle\n * @param preserveModulesRoot - The preserve modules root\n * @returns The bundle manifest\n */\nexport function getBundleManifest({\n pluginContext,\n bundle,\n moduleBase,\n preserveModulesRoot,\n}: {\n pluginContext: PluginContext,\n bundle: OutputBundle,\n moduleBase?: string,\n preserveModulesRoot?: boolean,\n}): Record<string, BundleManifestEntry> {\n\n const normalizer = createInputNormalizer({\n root: pluginContext.environment.config.root,\n removeExtension: DEFAULT_CONFIG.FILE_REGEX,\n preserveModulesRoot: preserveModulesRoot === true ? moduleBase : undefined,\n });\n\n if (!bundle) return {};\n\n // Track virtual modules to prevent duplicates\n const virtualModules = new Map<string, string>();\n\n const bundleManifest = Object.fromEntries(\n Object.entries(bundle)\n .map(([fileName, chunk]) => {\n if (chunk.type !== \"chunk\") return null as never;\n const chunkWithFacade = chunk as OutputChunk;\n \n // Get the module ID, preferring facadeModuleId\n const moduleId = chunkWithFacade.facadeModuleId || chunkWithFacade.moduleIds[0] || fileName;\n \n // Handle commonjs helpers specially - must be done before normalization\n if (moduleId.includes('commonjsHelpers')) {\n return [\n moduleId,\n {\n file: 'commonjs-runtime.js',\n name: 'commonjsHelpers',\n src: moduleId,\n isEntry: false\n }\n ];\n }\n \n // Normalize both paths, removing the root prefix\n let [normalizedId, sourcePath] = normalizer(moduleId);\n\n // For virtual modules, use a consistent naming scheme\n let finalFileName = fileName;\n if (moduleId.includes('?')) {\n const [basePath, query] = moduleId.split('?');\n const virtualPath = basePath.includes('node_modules') \n ? basePath.split('node_modules/')[1] \n : basePath;\n \n // Create a unique key for this virtual module\n const virtualKey = `${virtualPath}?${query}`;\n \n if (!virtualModules.has(virtualKey)) {\n // First time seeing this virtual module\n const virtualFileName = `${virtualPath.replace(/\\.js$/, '')}.${query}.js`;\n virtualModules.set(virtualKey, virtualFileName);\n }\n \n finalFileName = virtualModules.get(virtualKey)!;\n }\n // handle preserveModulesRoot\n if(normalizedId.startsWith('\\x00')){\n normalizedId = normalizedId.slice(1);\n }\n if(sourcePath.startsWith('/')){\n sourcePath = sourcePath.slice(1);\n }\n if(moduleBase && preserveModulesRoot && normalizedId?.startsWith(moduleBase + '/')) {\n normalizedId = normalizedId.slice(moduleBase.length + 1);\n }\n const bundleManifestEntry = [\n sourcePath,\n {\n file: finalFileName,\n name: normalizedId,\n src: sourcePath,\n isEntry: chunk.isEntry,\n ...(chunk.imports?.length > 0 ? { imports: chunk.imports } : {}),\n ...(chunk.dynamicImports?.length > 0 ? { dynamicImports: chunk.dynamicImports } : {}),\n ...(chunk.viteMetadata?.importedCss?.size ? {\n css: Array.from(chunk.viteMetadata.importedCss),\n } : {}),\n },\n ];\n return bundleManifestEntry;\n })\n .filter(Boolean)\n );\n return bundleManifest;\n}\n"],"names":[],"mappings":";;;;;;;;AAyBO,SAAS,iBAAkB,CAAA;AAAA,EAChC,aAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF,CAKwC,EAAA;AAEtC,EAAA,MAAM,aAAa,qBAAsB,CAAA;AAAA,IACvC,IAAA,EAAM,aAAc,CAAA,WAAA,CAAY,MAAO,CAAA,IAAA;AAAA,IACvC,iBAAiB,cAAe,CAAA,UAAA;AAAA,IAChC,mBAAA,EAAqB,mBAAwB,KAAA,IAAA,GAAO,UAAa,GAAA;AAAA,GAClE,CAAA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;AAAA,cAC5C;AAAC;AACP,OACF;AACA,MAAO,OAAA,mBAAA;AAAA,KACR,CACA,CAAA,MAAA,CAAO,OAAO;AAAA,GACnB;AACA,EAAO,OAAA,cAAA;AACT;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../plugin/html.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,eAAO,MAAM,IAAI,iBAAkB;IAAE,QAAQ,EAAE,GAAG,CAAA;CAAE,sBAOnD,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
import React__default from 'react';
|
|
7
|
+
|
|
8
|
+
const Html = ({ children }) => /* @__PURE__ */ React__default.createElement("html", null, /* @__PURE__ */ React__default.createElement("head", null), /* @__PURE__ */ React__default.createElement("body", null, /* @__PURE__ */ React__default.createElement("div", { id: "root" }, children)));
|
|
9
|
+
|
|
10
|
+
export { Html };
|
|
11
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sources":["../../plugin/html.tsx"],"sourcesContent":["import React from \"react\";\nexport const Html = ({ children }: { children: any }) => (\n <html>\n <head></head>\n <body>\n <div id=\"root\">{children}</div>\n </body>\n </html>\n);\n"],"names":["React"],"mappings":";;;;;;;AACO,MAAM,OAAO,CAAC,EAAE,UACrB,qBAAAA,cAAA,CAAA,aAAA,CAAC,8BACEA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,IAAK,CACN,kBAAAA,cAAA,CAAA,aAAA,CAAC,8BACEA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAI,IAAG,MAAQ,EAAA,EAAA,QAAS,CAC3B,CACF;;;;"}
|
|
@@ -9,5 +9,5 @@ export interface BuildLoaderOptions {
|
|
|
9
9
|
serverManifest: Manifest;
|
|
10
10
|
clientManifest: Manifest;
|
|
11
11
|
}
|
|
12
|
-
export declare function createBuildLoader({ root, userConfig, userOptions, pluginContext, serverManifest, clientManifest, }: BuildLoaderOptions): (id: string) => Promise<any>;
|
|
12
|
+
export declare function createBuildLoader({ root, userConfig: _userConfig, userOptions, pluginContext: _pluginContext, serverManifest, clientManifest, }: BuildLoaderOptions): (id: string) => Promise<any>;
|
|
13
13
|
//# sourceMappingURL=createBuildLoader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBuildLoader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/createBuildLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAGrC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,WAAW,EAAE,mBAAmB,CAAC;IACjC,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,UAAU,
|
|
1
|
+
{"version":3,"file":"createBuildLoader.d.ts","sourceRoot":"","sources":["../../../plugin/loader/createBuildLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAGrC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,WAAW,EAAE,mBAAmB,CAAC;IACjC,cAAc,EAAE,QAAQ,CAAC;IACzB,cAAc,EAAE,QAAQ,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,UAAU,EAAE,WAAW,EACvB,WAAW,EACX,aAAa,EAAE,cAAc,EAC7B,cAAc,EACd,cAAc,GACf,EAAE,kBAAkB,QAMmB,MAAM,kBAsC7C"}
|