vite-plugin-react-server 0.3.0 → 0.3.3

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.
Files changed (109) hide show
  1. package/README.md +73 -40
  2. package/dist/assertServerCondition.d.ts +2 -0
  3. package/dist/assertServerCondition.d.ts.map +1 -0
  4. package/dist/bin/patch.js +51 -0
  5. package/dist/bin/patch.js.map +1 -0
  6. package/dist/build/createBuildConfig.d.ts +7 -6
  7. package/dist/build/createBuildConfig.d.ts.map +1 -1
  8. package/dist/build/mergeInputs.d.ts +5 -0
  9. package/dist/build/mergeInputs.d.ts.map +1 -0
  10. package/dist/helpers/inputNormalizer.d.ts +6 -0
  11. package/dist/helpers/inputNormalizer.d.ts.map +1 -0
  12. package/dist/helpers/normalizedRelativePath.d.ts +3 -1
  13. package/dist/helpers/normalizedRelativePath.d.ts.map +1 -1
  14. package/dist/helpers/tryManifest.d.ts +10 -3
  15. package/dist/helpers/tryManifest.d.ts.map +1 -1
  16. package/dist/html/createPageLoader.d.ts.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/options.d.ts +13 -8
  19. package/dist/options.d.ts.map +1 -1
  20. package/dist/plugin.d.ts +2 -7
  21. package/dist/plugin.d.ts.map +1 -1
  22. package/dist/react-client/plugin.js +1 -1
  23. package/dist/react-server/plugin.d.ts.map +1 -1
  24. package/dist/react-server/plugin.js +108 -61
  25. package/dist/react-server/plugin.js.map +1 -1
  26. package/dist/src/build/createBuildConfig.js +44 -0
  27. package/dist/src/build/createBuildConfig.js.map +1 -0
  28. package/dist/src/build/mergeInputs.js +16 -0
  29. package/dist/src/build/mergeInputs.js.map +1 -0
  30. package/dist/src/checkFilesExist.js.map +1 -0
  31. package/dist/src/collect-css-manifest.js.map +1 -0
  32. package/dist/src/components.js.map +1 -0
  33. package/dist/src/getEnv.js.map +1 -0
  34. package/dist/src/helpers/inputNormalizer.js +11 -0
  35. package/dist/src/helpers/inputNormalizer.js.map +1 -0
  36. package/dist/src/helpers/normalizedRelativePath.js +34 -0
  37. package/dist/src/helpers/normalizedRelativePath.js.map +1 -0
  38. package/dist/src/helpers/tryManifest.js +27 -0
  39. package/dist/src/helpers/tryManifest.js.map +1 -0
  40. package/dist/{html → src/html}/createPageLoader.js +3 -1
  41. package/dist/src/html/createPageLoader.js.map +1 -0
  42. package/dist/{options.js → src/options.js} +80 -24
  43. package/dist/src/options.js.map +1 -0
  44. package/dist/src/react-server/createHandler.js.map +1 -0
  45. package/dist/src/react-server/createRscStream.js.map +1 -0
  46. package/dist/src/resolvePage.js.map +1 -0
  47. package/dist/src/resolveProps.js.map +1 -0
  48. package/dist/src/worker/createHtmlStream.js +62 -0
  49. package/dist/src/worker/createHtmlStream.js.map +1 -0
  50. package/dist/{worker → src/worker}/createWorker.js +9 -8
  51. package/dist/src/worker/createWorker.js.map +1 -0
  52. package/dist/src/worker/renderPages.js.map +1 -0
  53. package/dist/types.d.ts +7 -2
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/worker/createWorker.d.ts +8 -1
  56. package/dist/worker/createWorker.d.ts.map +1 -1
  57. package/dist/worker/loader.js +7 -0
  58. package/dist/worker/loader.js.map +1 -0
  59. package/dist/worker/worker.js +112 -0
  60. package/dist/worker/worker.js.map +1 -0
  61. package/package.json +108 -111
  62. package/patches/react-server-dom-esm+0.0.1.patch +14519 -0
  63. package/src/assertServerCondition.ts +13 -0
  64. package/src/build/createBuildConfig.ts +27 -44
  65. package/src/build/mergeInputs.ts +42 -0
  66. package/src/helpers/inputNormalizer.ts +22 -0
  67. package/src/helpers/normalizedRelativePath.ts +25 -25
  68. package/src/helpers/tryManifest.ts +19 -5
  69. package/src/html/createPageLoader.ts +2 -0
  70. package/src/options.ts +119 -47
  71. package/src/plugin.ts +4 -30
  72. package/src/react-server/createSsrHandler.ts +1 -1
  73. package/src/react-server/plugin.ts +116 -56
  74. package/src/types.ts +19 -1
  75. package/src/worker/createWorker.ts +12 -7
  76. package/tsconfig.json +2 -0
  77. package/dist/build/createBuildConfig.js +0 -55
  78. package/dist/build/createBuildConfig.js.map +0 -1
  79. package/dist/checkFilesExist.js.map +0 -1
  80. package/dist/collect-css-manifest.js.map +0 -1
  81. package/dist/components.js.map +0 -1
  82. package/dist/getEnv.js.map +0 -1
  83. package/dist/helpers/normalizedRelativePath.js +0 -31
  84. package/dist/helpers/normalizedRelativePath.js.map +0 -1
  85. package/dist/html/createPageLoader.js.map +0 -1
  86. package/dist/options.js.map +0 -1
  87. package/dist/plugin.js +0 -31
  88. package/dist/plugin.js.map +0 -1
  89. package/dist/react-server/createHandler.js.map +0 -1
  90. package/dist/react-server/createRscStream.js.map +0 -1
  91. package/dist/resolvePage.js.map +0 -1
  92. package/dist/resolveProps.js.map +0 -1
  93. package/dist/transformer/index.js +0 -54
  94. package/dist/transformer/index.js.map +0 -1
  95. package/dist/transformer/preserveDirectives.js +0 -72
  96. package/dist/transformer/preserveDirectives.js.map +0 -1
  97. package/dist/transformer/transformer.js +0 -80
  98. package/dist/transformer/transformer.js.map +0 -1
  99. package/dist/worker/createWorker.js.map +0 -1
  100. package/dist/worker/renderPages.js.map +0 -1
  101. /package/dist/{checkFilesExist.js → src/checkFilesExist.js} +0 -0
  102. /package/dist/{collect-css-manifest.js → src/collect-css-manifest.js} +0 -0
  103. /package/dist/{components.js → src/components.js} +0 -0
  104. /package/dist/{getEnv.js → src/getEnv.js} +0 -0
  105. /package/dist/{react-server → src/react-server}/createHandler.js +0 -0
  106. /package/dist/{react-server → src/react-server}/createRscStream.js +0 -0
  107. /package/dist/{resolvePage.js → src/resolvePage.js} +0 -0
  108. /package/dist/{resolveProps.js → src/resolveProps.js} +0 -0
  109. /package/dist/{worker → src/worker}/renderPages.js +0 -0
package/README.md CHANGED
@@ -1,12 +1,40 @@
1
1
  # Vite React Server Components Plugin
2
2
 
3
- A Vite plugin that enables React Server Components (RSC) streaming and static building of html pages. Uses experimental dependencies from React, specifically `react-server-dom-esm/server.node`.
3
+ A Vite plugin that enables React Server Components (RSC) streaming and static building of html pages. Uses experimental dependencies from React, specifically `react-server-dom-esm`.
4
4
 
5
5
  Temporary patch-package is included in this repository. Example project:
6
6
 
7
7
  the [mmcelebration.com project](https://github.com/nicobrinkkemper/mmc) is using this plugin. The build time for this website of roughly 200 html pages is a couple of seconds - depending on your machine.
8
8
 
9
- To achieve a simple workflow, it uses a node worker thread to generate the html for the pages. The reason for this is that we need to keep the client and server build processes separate - yet streaming data towards each other. Running the worker avoids running a server for the build process - and as such doesn't need to run a server to export all the html pages.
9
+ ## Canary first development
10
+
11
+ This plugin was developed using the react version currrently hosted on the official react github repository. You can
12
+ only get this version of react-server-dom-esm by actually building react from source. There's a patch system included
13
+ that allows you to download the stub version of react-server-dom-esm and apply the patch to it.
14
+
15
+ ```bash
16
+ npm install react-server-dom-esm
17
+ ```
18
+ This package exists, but is empty! So, we need to patch it.
19
+
20
+ ```bash
21
+ npx vite-react-stream/patch
22
+ ```
23
+ This will do two things:
24
+ - Look for your installed react version
25
+ - Change the patch around so it matches your react version
26
+ - Writes a file to patches/react-server-dom-esm+YOUR-REACT-VERSION.patch
27
+ ```bash
28
+ npm install patch-package --save-dev
29
+ ```
30
+ Add to postinstall script in package.json: (you need to do this yourself)
31
+ ```json
32
+ "postinstall": "patch-package"
33
+ ```
34
+ Now anytime you run install, it will patch the react-server-dom-esm package. Wait until the package is released
35
+ and you can remove the patch-package script.
36
+
37
+ If you don't want to rely on this, you can also build react from source yourself and run `npm run link` where the package.json is, then `npm link react-server-dom-esm` where you need to use it. However, make sure to also link the react and react-dom package as well or the versions will mismatch (hence the patch-package system).
10
38
 
11
39
  ## Features
12
40
 
@@ -19,64 +47,69 @@ To achieve a simple workflow, it uses a node worker thread to generate the html
19
47
  npm install vite-plugin-react-server
20
48
  ```
21
49
 
22
-
23
50
  ## Usage
24
51
 
25
52
  Single vite.config.ts file for server and client build - though you can split it up if you want.
26
53
  The import `import { viteReactStreamPlugin } from 'vite-plugin-react-server'` will import the
27
54
  right client/server plugin based on the NODE_OPTIONS environment variable.
28
55
 
56
+ Checkout the [template directory](./template) for a complete example.
57
+
58
+
59
+ ## Configuration
60
+ To keep the client and server build processes easy to seperate, I suggest creating two vite.config.ts files and import the config in both. Let's make the stream plugin config file and name it `.tsx`. Vite config files can't end with `.tsx` but our own files can.
61
+
29
62
  ```typescript
30
- // vite.config.ts
63
+ // vite.react-server.config.ts
31
64
  import { defineConfig } from 'vite'
32
- import { viteReactStreamPlugin } from 'vite-plugin-react-server'
65
+ import type { Options } from 'vite-plugin-react-server'
33
66
 
34
67
  // Custom router example
35
- const createRouter = (fileName: string) => (url: string) => {
36
- try {
37
- return new URL(`file://./src/page${url}/${fileName}`).pathname
38
- } catch (e) {
39
- return `src/page/404/${fileName}`
40
- }
41
- };
68
+ const createRouter = (file: 'props.ts' | 'Page.tsx') => (url: string) => {
69
+ console.log(url)
70
+ if(url.includes('bidoof'))
71
+ return `src/page/bidoof/${file}`
72
+ if(url === '/index.rsc')
73
+ return `src/page/${file}`;
74
+ return `src/page/404/${file}`;
75
+ }
76
+
77
+ export const streamPluginOptions: Options = {
78
+ moduleBase: "src",
79
+ Page: createRouter('Page.tsx'),
80
+ props: createRouter('props.ts'),
81
+ pageExportName: "Page",
82
+ propsExportName: "props",
83
+ }
84
+ ```
85
+ Now let's make the client build config file.
86
+ ```typescript
87
+ // vite.config.ts
88
+ import { defineConfig } from 'vite'
89
+ import { viteReactStreamPlugin } from 'vite-plugin-react-server/client'
90
+ import { streamPluginOptions } from './vite.react-server.config.js'
91
+
42
92
 
43
93
  export default defineConfig({
44
94
  plugins: [
45
- viteReactStreamPlugin({
46
- moduleBase: "src",
47
- Page: createRouter("page.tsx"),
48
- props: createRouter("props.ts"),
49
- pageExportName: "Page",
50
- propsExportName: "props",
51
- build: {
52
- client: "dist/client",
53
- server: "dist/server",
54
- pages: ()=>["/"]
55
- },
56
- })
95
+ viteReactStreamPlugin(streamPluginOptions)
57
96
  ]
58
97
  })
59
98
  ```
60
99
 
61
- If you want to import the right plugin directly, you can do so like this:
100
+ And the server build config file:
62
101
 
63
102
  ```typescript
64
- // vite.react.config.ts
65
- import type { Options } from 'vite-plugin-react-server/server'
103
+ // vite.server.config.ts
104
+ import { defineConfig } from 'vite'
105
+ import { viteReactStreamPlugin } from 'vite-plugin-react-server/server'
106
+ import { streamPluginOptions } from './vite.react-server.config.js'
66
107
 
67
- export const streamPluginOptions: Options = {
68
- moduleBase: "src",
69
- Page: `src/page/index.tsx`,
70
- props: `src/page/index.tsx`,
71
- pageExportName: "Page",
72
- propsExportName: "props",
73
- Html: ({children})=>(<html><body>{children}</body></html>),
74
- build: {
75
- client: "dist/client",
76
- server: "dist/server",
77
- pages: ()=>["/"]
78
- },
79
- }
108
+ export default defineConfig({
109
+ plugins: [
110
+ viteReactStreamPlugin(streamPluginOptions)
111
+ ]
112
+ })
80
113
  ```
81
114
 
82
115
  ```typescript
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=assertServerCondition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertServerCondition.d.ts","sourceRoot":"","sources":["../src/assertServerCondition.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ const PATCH_RECONCILER_VERSION = "19.1.0-experimental-b3a95caf-20250113";
5
+ async function patchReactExperimental() {
6
+ try {
7
+ const reactPkg = JSON.parse(
8
+ await fs.readFile(
9
+ path.resolve(process.cwd(), "node_modules/react/package.json"),
10
+ "utf-8"
11
+ )
12
+ );
13
+ const installedVersion = reactPkg.version;
14
+ const ourPatchPath = path.resolve(__dirname, "../patches/react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch");
15
+ let patchContent = await fs.readFile(ourPatchPath, "utf-8");
16
+ patchContent = patchContent.replace(
17
+ new RegExp(PATCH_RECONCILER_VERSION, "g"),
18
+ installedVersion
19
+ );
20
+ const userPatchesDir = path.resolve(process.cwd(), "patches");
21
+ await fs.mkdir(userPatchesDir, { recursive: true });
22
+ const newFileName = `react-server-dom-esm+${installedVersion}.patch`;
23
+ const newPatchPath = path.resolve(userPatchesDir, newFileName);
24
+ await fs.writeFile(newPatchPath, patchContent);
25
+ console.log(`
26
+ ✅ Created patch file for React Server DOM ESM
27
+ Location: patches/${newFileName}
28
+
29
+ Next steps:
30
+ 1. Install patch-package:
31
+ npm install patch-package --save-dev
32
+
33
+ 2. Add to package.json:
34
+ "postinstall": "patch-package"
35
+
36
+ 3. Run:
37
+ npm install
38
+
39
+ The patch will be applied automatically on install.
40
+ `);
41
+ return true;
42
+ } catch (e) {
43
+ console.error("Failed to create patch:", e);
44
+ process.exit(1);
45
+ }
46
+ }
47
+ patchReactExperimental().catch((e) => {
48
+ console.error("Unexpected error:", e);
49
+ process.exit(1);
50
+ });
51
+ //# sourceMappingURL=patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.js","sources":["../../bin/patch.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\n\nconst PATCH_RECONCILER_VERSION = '19.1.0-experimental-b3a95caf-20250113'\n\nasync function patchReactExperimental() {\n try {\n // Read installed React version from user's project\n const reactPkg = JSON.parse(\n await fs.readFile(\n path.resolve(process.cwd(), 'node_modules/react/package.json'),\n 'utf-8'\n )\n )\n const installedVersion = reactPkg.version\n\n // Get our patch file\n const ourPatchPath = path.resolve(__dirname, '../patches/react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch')\n let patchContent = await fs.readFile(ourPatchPath, 'utf-8')\n\n // Replace version strings to match installed React\n patchContent = patchContent.replace(\n new RegExp(PATCH_RECONCILER_VERSION, 'g'),\n installedVersion\n )\n\n // Create patches dir in user's project\n const userPatchesDir = path.resolve(process.cwd(), 'patches')\n await fs.mkdir(userPatchesDir, { recursive: true })\n\n // Write the patch file\n const newFileName = `react-server-dom-esm+${installedVersion}.patch`\n const newPatchPath = path.resolve(userPatchesDir, newFileName)\n await fs.writeFile(newPatchPath, patchContent)\n\n console.log(`\n✅ Created patch file for React Server DOM ESM\n Location: patches/${newFileName}\n\nNext steps:\n1. Install patch-package:\n npm install patch-package --save-dev\n\n2. Add to package.json:\n \"postinstall\": \"patch-package\"\n\n3. Run:\n npm install\n\nThe patch will be applied automatically on install.\n`)\n return true\n } catch (e) {\n console.error('Failed to create patch:', e)\n process.exit(1)\n }\n}\n\npatchReactExperimental().catch((e) => {\n console.error('Unexpected error:', e)\n process.exit(1)\n}) "],"names":[],"mappings":";;;AAIA,MAAM,2BAA2B;AAEjC,eAAe,yBAAyB;AAClC,MAAA;AAEF,UAAM,WAAW,KAAK;AAAA,MACpB,MAAM,GAAG;AAAA,QACP,KAAK,QAAQ,QAAQ,IAAA,GAAO,iCAAiC;AAAA,QAC7D;AAAA,MAAA;AAAA,IAEJ;AACA,UAAM,mBAAmB,SAAS;AAGlC,UAAM,eAAe,KAAK,QAAQ,WAAW,4EAA4E;AACzH,QAAI,eAAe,MAAM,GAAG,SAAS,cAAc,OAAO;AAG1D,mBAAe,aAAa;AAAA,MAC1B,IAAI,OAAO,0BAA0B,GAAG;AAAA,MACxC;AAAA,IACF;AAGA,UAAM,iBAAiB,KAAK,QAAQ,QAAQ,OAAO,SAAS;AAC5D,UAAM,GAAG,MAAM,gBAAgB,EAAE,WAAW,MAAM;AAG5C,UAAA,cAAc,wBAAwB,gBAAgB;AAC5D,UAAM,eAAe,KAAK,QAAQ,gBAAgB,WAAW;AACvD,UAAA,GAAG,UAAU,cAAc,YAAY;AAE7C,YAAQ,IAAI;AAAA;AAAA,uBAEO,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAajC;AACU,WAAA;AAAA,WACA,GAAG;AACF,YAAA,MAAM,2BAA2B,CAAC;AAC1C,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;AAEA,yBAAyB,MAAM,CAAC,MAAM;AAC5B,UAAA,MAAM,qBAAqB,CAAC;AACpC,UAAQ,KAAK,CAAC;AAChB,CAAC;"}
@@ -1,12 +1,13 @@
1
1
  import type { InlineConfig } from "vite";
2
- import type { StreamPluginOptions } from "../types.js";
2
+ import type { ResolvedUserConfig, ResolvedUserOptions } from "../types.js";
3
+ import type { InputOption } from "rollup";
3
4
  type CreateBuildConfigOptions = {
5
+ input: InputOption;
6
+ userOptions: ResolvedUserOptions;
7
+ userConfig: ResolvedUserConfig;
4
8
  root: string;
5
- base: string;
6
- outDir: string;
7
- entries: string[];
8
- options?: StreamPluginOptions;
9
+ moduleBaseExceptions: string[];
9
10
  };
10
- export declare function createBuildConfig({ root, base, outDir, entries, options, }: CreateBuildConfigOptions): InlineConfig;
11
+ export declare function createBuildConfig({ root, input, userOptions, userConfig, moduleBaseExceptions }: CreateBuildConfigOptions): InlineConfig;
11
12
  export {};
12
13
  //# sourceMappingURL=createBuildConfig.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createBuildConfig.d.ts","sourceRoot":"","sources":["../../src/build/createBuildConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,EACP,OAAO,GACR,EAAE,wBAAwB,gBAoD1B"}
1
+ {"version":3,"file":"createBuildConfig.d.ts","sourceRoot":"","sources":["../../src/build/createBuildConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAI1C,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,WAAW,EAAG,mBAAmB,CAAC;IAClC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAGF,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,KAAK,EACL,WAAW,EACX,UAAU,EACV,oBAAoB,EACrB,EAAE,wBAAwB,gBAmC1B"}
@@ -0,0 +1,5 @@
1
+ import type { InputOption } from "rollup";
2
+ export declare const mergeAsArray: (entries: InputOption) => string[];
3
+ export declare const mergeAsObject: (entries: InputOption) => Record<string, string>;
4
+ export declare const mergeInputs: (input: InputOption, input2: InputOption | undefined) => InputOption;
5
+ //# sourceMappingURL=mergeInputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeInputs.d.ts","sourceRoot":"","sources":["../../src/build/mergeInputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,eAAO,MAAM,YAAY,YAAa,WAAW,aAQhD,CAAC;AACF,eAAO,MAAM,aAAa,YAAa,WAAW,2BAQjD,CAAC;AAEF,eAAO,MAAM,WAAW,UACf,WAAW,UACV,WAAW,GAAG,SAAS,gBAkBhC,CAAC"}
@@ -0,0 +1,6 @@
1
+ type NormalizedInputOptions = {
2
+ root?: string;
3
+ };
4
+ export declare const createInputNormalizer: ({ root, }?: NormalizedInputOptions) => ([key, path]: [string, string]) => string[];
5
+ export {};
6
+ //# sourceMappingURL=inputNormalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputNormalizer.d.ts","sourceRoot":"","sources":["../../src/helpers/inputNormalizer.ts"],"names":[],"mappings":"AAEA,KAAK,sBAAsB,GAAG;IAE5B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAI3B,sBAAsB,mBAEb,CAAC,MAAM,EAAE,MAAM,CAAC,aAQ3B,CAAC"}
@@ -1,8 +1,10 @@
1
1
  type NormalizedRelativePathOptions = {
2
2
  root: string;
3
- outDir: string | string[];
3
+ outDir: string;
4
4
  moduleBase: string;
5
5
  noLeadingSlash: boolean;
6
+ noTrailingSlash: boolean;
7
+ moduleBaseExceptions: string[];
6
8
  };
7
9
  export declare const createNormalizedRelativePath: (options?: NormalizedRelativePathOptions) => (path: string) => string;
8
10
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"normalizedRelativePath.d.ts","sourceRoot":"","sources":["../../src/helpers/normalizedRelativePath.ts"],"names":[],"mappings":"AAEA,KAAK,6BAA6B,GAAG;IAEnC,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE1B,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC9B,6BAA6B,YA2CxB,MAAM,WACrB,CAAC"}
1
+ {"version":3,"file":"normalizedRelativePath.d.ts","sourceRoot":"","sources":["../../src/helpers/normalizedRelativePath.ts"],"names":[],"mappings":"AAEA,KAAK,6BAA6B,GAAG;IAEnC,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,cAAc,EAAE,OAAO,CAAC;IAExB,eAAe,EAAE,OAAO,CAAC;IAEzB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,4BAA4B,aAC9B,6BAA6B,YAuCxB,MAAM,WACrB,CAAC"}
@@ -1,8 +1,15 @@
1
- type TryManifestOptions = {
1
+ import type { Manifest } from "vite";
2
+ type TryManifestOptions<SSR extends boolean> = {
2
3
  root: string;
3
4
  outDir: string;
4
- ssrManifest: boolean;
5
+ ssrManifest: SSR;
6
+ };
7
+ export declare function tryManifest<SSR extends boolean>(options: TryManifestOptions<SSR>): {
8
+ type: "success";
9
+ manifest: SSR extends true ? Record<string, string[]> : Manifest;
10
+ } | {
11
+ type: "error";
12
+ error: Error;
5
13
  };
6
- export declare function tryManifest(options: TryManifestOptions): any;
7
14
  export {};
8
15
  //# sourceMappingURL=tryManifest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tryManifest.d.ts","sourceRoot":"","sources":["../../src/helpers/tryManifest.ts"],"names":[],"mappings":"AAGA,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,OAatD"}
1
+ {"version":3,"file":"tryManifest.d.ts","sourceRoot":"","sources":["../../src/helpers/tryManifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAErC,KAAK,kBAAkB,CAAC,GAAG,SAAS,OAAO,IAAI;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,GAAG,SAAS,OAAO,EAAE,OAAO,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG;IAClF,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,GAAG,SAAS,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,QAAQ,CAAC;CAClE,GAAG;IACF,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd,CAoBA"}
@@ -1 +1 @@
1
- {"version":3,"file":"createPageLoader.d.ts","sourceRoot":"","sources":["../../src/html/createPageLoader.ts"],"names":[],"mappings":"AAQA,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,mBAAmB,wFAM7B,0BAA0B,WAqBR,MAAM,iBAE1B,CAAC;AAEF,eAAO,MAAM,gBAAgB,wHAS1B,uBAAuB,UAON,MAAM;;;EAwBzB,CAAC"}
1
+ {"version":3,"file":"createPageLoader.d.ts","sourceRoot":"","sources":["../../src/html/createPageLoader.ts"],"names":[],"mappings":"AAQA,KAAK,uBAAuB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,mBAAmB,wFAM7B,0BAA0B,WAqBR,MAAM,iBAE1B,CAAC;AAEF,eAAO,MAAM,gBAAgB,wHAS1B,uBAAuB,UASN,MAAM;;;EAwBzB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { reactStreamPlugin } from "./plugin.js";
1
+ import { reactStreamPlugin } from "./react-server/plugin.js";
2
2
  export {
3
3
  reactStreamPlugin
4
4
  };
package/dist/options.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ConfigEnv, ResolvedConfig, UserConfig } from "vite";
2
- import type { ResolvedUserOptions, StreamPluginOptions } from "./types.js";
2
+ import type { ResolvedUserConfig, ResolvedUserOptions, StreamPluginOptions } from "./types.js";
3
+ import type { InputOption } from "rollup";
3
4
  export declare const DEFAULT_CONFIG: {
4
5
  readonly FILE_REGEX: RegExp;
5
6
  readonly CLIENT_ASSETS_DIR: "assets";
@@ -12,8 +13,8 @@ export declare const DEFAULT_CONFIG: {
12
13
  readonly CLIENT_ENTRY: "/src/client.tsx";
13
14
  readonly PAGE_EXPORT: "Page";
14
15
  readonly PROPS_EXPORT: "props";
15
- readonly WORKER_PATH: "worker/worker.tsx";
16
- readonly LOADER_PATH: "worker/loader.ts";
16
+ readonly WORKER_PATH: "vite-plugin-react-server/worker";
17
+ readonly LOADER_PATH: "vite-plugin-react-server/loader";
17
18
  readonly RSC_EXTENSION: ".rsc";
18
19
  readonly HTML: ({ children }: {
19
20
  children: any;
@@ -32,6 +33,10 @@ export declare const DEFAULT_CONFIG: {
32
33
  readonly client: "dist/client";
33
34
  readonly server: "dist/server";
34
35
  };
36
+ readonly AUTO_DISCOVER: {
37
+ readonly pagePattern: "**/*.page.tsx";
38
+ readonly propsPattern: "**/*.props.ts";
39
+ };
35
40
  };
36
41
  export declare const resolveConfig: <T extends ResolvedConfig>(config: T, resolvedUserConfig: UserConfig, userOptions: ResolvedUserOptions) => T & {
37
42
  build: {
@@ -62,19 +67,19 @@ export declare const resolveConfig: <T extends ResolvedConfig>(config: T, resolv
62
67
  chunkSizeWarningLimit: number;
63
68
  };
64
69
  };
65
- export declare const resolveUserConfig: (condition: "react-client" | "react-server", input: string[], config: UserConfig, configEnv: ConfigEnv, userOptions: ResolvedUserOptions) => {
70
+ export declare const resolveUserConfig: (condition: "react-client" | "react-server", input: InputOption, config: UserConfig, configEnv: ConfigEnv, userOptions: ResolvedUserOptions) => {
66
71
  type: "error";
67
72
  error: Error;
68
73
  } | {
69
74
  type: "success";
70
- userConfig: Required<Pick<UserConfig, "root" | "build" | "mode">> & Omit<UserConfig, "root" | "build" | "mode">;
75
+ userConfig: ResolvedUserConfig;
71
76
  };
72
77
  export declare const resolveOptions: (options: StreamPluginOptions) => {
73
- type: "error";
74
- error: Error;
75
- } | {
76
78
  type: "success";
77
79
  userOptions: ResolvedUserOptions;
80
+ } | {
81
+ type: "error";
82
+ error: Error;
78
83
  };
79
84
  export declare function resolvePages(pages: ResolvedUserOptions["build"]["pages"]): Promise<{
80
85
  type: "success";
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE3E,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;kCAgBJ;QAAE,QAAQ,EAAE,GAAG,CAAA;KAAE;;;;;;;;;;;;;;;CAe9B,CAAC;AAEX,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,cAAc,UAC5C,CAAC,sBACW,UAAU,eACjB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASjC,CAAC;AAEF,eAAO,MAAM,iBAAiB,cACjB,cAAc,GAAG,cAAc,SACnC,MAAM,EAAE,UACP,UAAU,aACP,SAAS,eACP,mBAAmB,KAE9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/B;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC,GAC/D,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC;CA2FnD,CAAC;AAEF,eAAO,MAAM,cAAc,YAChB,mBAAmB,KAE1B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/B;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,mBAAmB,CAAC;CA6FtC,CAAC;AAEF,wBAAsB,YAAY,CAChC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,GAC3C,OAAO,CACN;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd,CACJ,CAmFA"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;kCAgBJ;QAAE,QAAQ,EAAE,GAAG,CAAA;KAAE;;;;;;;;;;;;;;;;;;;CAmB9B,CAAC;AAEX,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,cAAc,UAC5C,CAAC,sBACW,UAAU,eACjB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CASjC,CAAC;AAEF,eAAO,MAAM,iBAAiB,cACjB,cAAc,GAAG,cAAc,SACnC,WAAW,UACV,UAAU,aACP,SAAS,eACP,mBAAmB,KAE9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAC/B;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,kBAAkB,CAAC;CAwGpC,CAAC;AAEF,eAAO,MAAM,cAAc,YAChB,mBAAmB,KAE1B;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,mBAAmB,CAAC;CAClC,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CAiJlB,CAAC;AAEF,wBAAsB,YAAY,CAChC,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,GAC3C,OAAO,CACN;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd,CACJ,CAmFA"}
package/dist/plugin.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- import type { StreamPluginOptions } from "./types.js";
2
- export declare const getCondition: (options?: {
3
- env?: typeof process.env;
4
- }) => "server" | "client";
5
- export declare const reactStreamPlugin: (options: StreamPluginOptions) => Promise<(import("rollup").Plugin<any> | import("vite").Plugin<any> | Promise<import("vite").Plugin<any> & import("rollup").Plugin<any> & {
6
- meta: import("./types.js").ReactStreamPluginMeta;
7
- }>)[] | Promise<import("vite").Plugin<any>>[]>;
1
+ import "./assertServerCondition.js";
2
+ export { reactStreamPlugin } from "./react-server/plugin.js";
8
3
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,YAAY,aAAa;IAAE,GAAG,CAAC,EAAE,OAAO,OAAO,CAAC,GAAG,CAAA;CAAE,wBAGjE,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAmB,mBAAmB;;8CAoBnE,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { resolveOptions, resolvePages, resolveUserConfig } from "../options.js";
1
+ import { resolveOptions, resolvePages, resolveUserConfig } from "../src/options.js";
2
2
  async function reactStreamPlugin(options) {
3
3
  const resolvedOptions = resolveOptions(options);
4
4
  if (resolvedOptions.type === "error") {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/react-server/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAY,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAa3D,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA0BvD,wBAAsB,iBAAiB,CACrC,OAAO,GAAE,mBAA+C,GACvD,OAAO,CAAC,UAAU,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC,CA4StE"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/react-server/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAY,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAC;AAa3D,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA6BvD,wBAAsB,iBAAiB,CACrC,OAAO,GAAE,mBAA+C,GACvD,OAAO,CAAC,UAAU,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC,CAqWtE"}