@vitejs/plugin-rsc 0.4.26 → 0.4.28
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 +34 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{plugin-DmahacLo.d.ts → plugin-BFcMxUSS.d.ts} +7 -2
- package/dist/{plugin-uOrnsu6L.js → plugin-iKgvucKS.js} +27 -9
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.js +2 -2
- package/package.json +3 -3
- package/types/index.d.ts +7 -0
package/README.md
CHANGED
|
@@ -168,6 +168,11 @@ export default async function handler(request: Request): Promise<Response> {
|
|
|
168
168
|
},
|
|
169
169
|
})
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
// add `import.meta.hot.accept` to handle server module change efficiently
|
|
173
|
+
if (import.meta.hot) {
|
|
174
|
+
import.meta.hot.accept()
|
|
175
|
+
}
|
|
171
176
|
```
|
|
172
177
|
|
|
173
178
|
- [`entry.ssr.tsx`](./examples/starter/src/framework/entry.ssr.tsx)
|
|
@@ -355,6 +360,8 @@ import.meta.hot.on('rsc:update', async () => {
|
|
|
355
360
|
|
|
356
361
|
### `@vitejs/plugin-rsc`
|
|
357
362
|
|
|
363
|
+
- Type: `rsc: (options?: RscPluginOptions) => Plugin[]`;
|
|
364
|
+
|
|
358
365
|
```js
|
|
359
366
|
import rsc from '@vitejs/plugin-rsc'
|
|
360
367
|
import { defineConfig } from 'vite'
|
|
@@ -390,8 +397,15 @@ export default defineConfig({
|
|
|
390
397
|
// for example, to obtain a key through environment variable during runtime.
|
|
391
398
|
// cf. https://nextjs.org/docs/app/guides/data-security#overwriting-encryption-keys-advanced
|
|
392
399
|
defineEncryptionKey: 'process.env.MY_ENCRYPTION_KEY',
|
|
400
|
+
|
|
401
|
+
// see `RscPluginOptions` for full options ...
|
|
393
402
|
}),
|
|
394
403
|
],
|
|
404
|
+
// the same options can be also specified via top-level `rsc` property.
|
|
405
|
+
// this allows other plugin to set options via `config` hook.
|
|
406
|
+
rsc: {
|
|
407
|
+
// ...
|
|
408
|
+
},
|
|
395
409
|
})
|
|
396
410
|
```
|
|
397
411
|
|
|
@@ -508,6 +522,26 @@ export default function myRscFrameworkPlugin() {
|
|
|
508
522
|
}
|
|
509
523
|
```
|
|
510
524
|
|
|
525
|
+
## Typescript
|
|
526
|
+
|
|
527
|
+
Types for global API are defined in `@vitejs/plugin-rsc/types`. For example, you can add it to `tsconfig.json` to have types for `import.meta.viteRsc` APIs:
|
|
528
|
+
|
|
529
|
+
```json
|
|
530
|
+
{
|
|
531
|
+
"compilerOptions": {
|
|
532
|
+
"types": ["vite/client", "@vitejs/plugin-rsc/types"]
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
```ts
|
|
538
|
+
import.meta.viteRsc.loadModule
|
|
539
|
+
// ^^^^^^^^^^
|
|
540
|
+
// <T>(environmentName: string, entryName: string) => Promise<T>
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
See also [Vite documentation](https://vite.dev/guide/api-hmr.html#intellisense-for-typescript) for `vite/client` types.
|
|
544
|
+
|
|
511
545
|
## Credits
|
|
512
546
|
|
|
513
547
|
This project builds on fundamental techniques and insights from pioneering Vite RSC implementations.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RscPluginOptions, vitePluginRsc } from "./plugin-
|
|
1
|
+
import { PluginApi, RscPluginOptions, getPluginApi, vitePluginRsc } from "./plugin-BFcMxUSS.js";
|
|
2
2
|
import MagicString from "magic-string";
|
|
3
3
|
import { Program } from "estree";
|
|
4
4
|
|
|
@@ -21,4 +21,4 @@ declare function transformHoistInlineDirective(input: string, ast: Program, {
|
|
|
21
21
|
names: string[];
|
|
22
22
|
};
|
|
23
23
|
//#endregion
|
|
24
|
-
export { type RscPluginOptions, vitePluginRsc as default, transformHoistInlineDirective };
|
|
24
|
+
export { type PluginApi, type RscPluginOptions, vitePluginRsc as default, getPluginApi, transformHoistInlineDirective };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import { transformHoistInlineDirective, vitePluginRsc } from "./plugin-
|
|
3
|
+
import { getPluginApi, transformHoistInlineDirective, vitePluginRsc } from "./plugin-iKgvucKS.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./shared-BWHxNw3Q.js";
|
|
7
7
|
|
|
8
|
-
export { vitePluginRsc as default, transformHoistInlineDirective };
|
|
8
|
+
export { vitePluginRsc as default, getPluginApi, transformHoistInlineDirective };
|
|
@@ -88,7 +88,7 @@ type RscPluginOptions = {
|
|
|
88
88
|
/**
|
|
89
89
|
* use `Plugin.buildApp` hook (introduced on Vite 7) instead of `builder.buildApp` configuration
|
|
90
90
|
* for better composability with other plugins.
|
|
91
|
-
* @default
|
|
91
|
+
* @default true since Vite 7
|
|
92
92
|
*/
|
|
93
93
|
useBuildAppHook?: boolean;
|
|
94
94
|
/**
|
|
@@ -117,6 +117,11 @@ type RscPluginOptions = {
|
|
|
117
117
|
serverChunk: string;
|
|
118
118
|
}) => string | undefined;
|
|
119
119
|
};
|
|
120
|
+
type PluginApi = {
|
|
121
|
+
manager: RscPluginManager;
|
|
122
|
+
};
|
|
123
|
+
/** @experimental */
|
|
124
|
+
declare function getPluginApi(config: Pick<ResolvedConfig, "plugins">): PluginApi | undefined;
|
|
120
125
|
/** @experimental */
|
|
121
126
|
declare function vitePluginRscMinimal(rscPluginOptions?: RscPluginOptions, manager?: RscPluginManager): Plugin[];
|
|
122
127
|
declare function vitePluginRsc(rscPluginOptions?: RscPluginOptions): Plugin[];
|
|
@@ -151,4 +156,4 @@ declare function transformRscCssExport(options: {
|
|
|
151
156
|
output: MagicString;
|
|
152
157
|
} | undefined>;
|
|
153
158
|
//#endregion
|
|
154
|
-
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, type RscPluginManager, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
|
|
159
|
+
export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, type RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
|
|
@@ -675,11 +675,17 @@ var RscPluginManager = class {
|
|
|
675
675
|
}
|
|
676
676
|
};
|
|
677
677
|
/** @experimental */
|
|
678
|
+
function getPluginApi(config) {
|
|
679
|
+
const plugin = config.plugins.find((p) => p.name === "rsc:minimal");
|
|
680
|
+
return plugin?.api;
|
|
681
|
+
}
|
|
682
|
+
/** @experimental */
|
|
678
683
|
function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginManager()) {
|
|
679
684
|
return [
|
|
680
685
|
{
|
|
681
686
|
name: "rsc:minimal",
|
|
682
687
|
enforce: "pre",
|
|
688
|
+
api: { manager },
|
|
683
689
|
async config() {
|
|
684
690
|
await esModuleLexer.init;
|
|
685
691
|
},
|
|
@@ -703,7 +709,8 @@ function vitePluginRscMinimal(rscPluginOptions = {}, manager = new RscPluginMana
|
|
|
703
709
|
...vitePluginRscCore(),
|
|
704
710
|
...vitePluginUseClient(rscPluginOptions, manager),
|
|
705
711
|
...vitePluginUseServer(rscPluginOptions, manager),
|
|
706
|
-
...vitePluginDefineEncryptionKey(rscPluginOptions)
|
|
712
|
+
...vitePluginDefineEncryptionKey(rscPluginOptions),
|
|
713
|
+
scanBuildStripPlugin({ manager })
|
|
707
714
|
];
|
|
708
715
|
}
|
|
709
716
|
function vitePluginRsc(rscPluginOptions = {}) {
|
|
@@ -749,6 +756,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
749
756
|
{
|
|
750
757
|
name: "rsc",
|
|
751
758
|
async config(config, env) {
|
|
759
|
+
if (config.rsc) Object.assign(rscPluginOptions, vite.mergeConfig(config.rsc, rscPluginOptions));
|
|
752
760
|
const result = await crawlFrameworkPkgs({
|
|
753
761
|
root: process.cwd(),
|
|
754
762
|
isBuild: env.command === "build",
|
|
@@ -767,7 +775,7 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
767
775
|
...result.ssr.noExternal.sort()
|
|
768
776
|
];
|
|
769
777
|
return {
|
|
770
|
-
appType: "custom",
|
|
778
|
+
appType: config.appType ?? "custom",
|
|
771
779
|
define: { "import.meta.env.__vite_rsc_build__": JSON.stringify(env.command === "build") },
|
|
772
780
|
environments: {
|
|
773
781
|
client: {
|
|
@@ -825,11 +833,18 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
825
833
|
builder: {
|
|
826
834
|
sharedPlugins: true,
|
|
827
835
|
sharedConfigBuild: true,
|
|
828
|
-
buildApp
|
|
836
|
+
async buildApp(builder) {
|
|
837
|
+
if (!rscPluginOptions.useBuildAppHook) await buildApp(builder);
|
|
838
|
+
}
|
|
829
839
|
}
|
|
830
840
|
};
|
|
831
841
|
},
|
|
832
|
-
|
|
842
|
+
configResolved() {
|
|
843
|
+
if (Number(vite.version.split(".")[0]) >= 7) rscPluginOptions.useBuildAppHook ??= true;
|
|
844
|
+
},
|
|
845
|
+
buildApp: { async handler(builder) {
|
|
846
|
+
if (rscPluginOptions.useBuildAppHook) await buildApp(builder);
|
|
847
|
+
} },
|
|
833
848
|
configureServer(server) {
|
|
834
849
|
globalThis.__viteRscDevServer = server;
|
|
835
850
|
const oldSend = server.environments.client.hot.send;
|
|
@@ -1011,8 +1026,8 @@ function vitePluginRsc(rscPluginOptions = {}) {
|
|
|
1011
1026
|
},
|
|
1012
1027
|
{
|
|
1013
1028
|
name: "vite-rsc-load-module-dev-proxy",
|
|
1014
|
-
apply: () => !!rscPluginOptions.loadModuleDevProxy,
|
|
1015
1029
|
configureServer(server) {
|
|
1030
|
+
if (!rscPluginOptions.loadModuleDevProxy) return;
|
|
1016
1031
|
async function createHandler(url) {
|
|
1017
1032
|
const { environmentName, entryName } = Object.fromEntries(url.searchParams);
|
|
1018
1033
|
assert(environmentName);
|
|
@@ -1184,7 +1199,10 @@ import.meta.hot.on("rsc:update", () => {
|
|
|
1184
1199
|
...vitePluginRscMinimal(rscPluginOptions, manager),
|
|
1185
1200
|
...vitePluginFindSourceMapURL(),
|
|
1186
1201
|
...vitePluginRscCss(rscPluginOptions, manager),
|
|
1187
|
-
|
|
1202
|
+
{
|
|
1203
|
+
...validateImportPlugin(),
|
|
1204
|
+
apply: () => rscPluginOptions.validateImports !== false
|
|
1205
|
+
},
|
|
1188
1206
|
scanBuildStripPlugin({ manager }),
|
|
1189
1207
|
...cjsModuleRunnerPlugin(),
|
|
1190
1208
|
...globalAsyncLocalStoragePlugin()
|
|
@@ -1476,7 +1494,7 @@ function vitePluginDefineEncryptionKey(useServerPluginOptions) {
|
|
|
1476
1494
|
},
|
|
1477
1495
|
renderChunk(code, chunk) {
|
|
1478
1496
|
if (code.includes(KEY_PLACEHOLDER)) {
|
|
1479
|
-
assert.equal(this.environment.name,
|
|
1497
|
+
assert.equal(this.environment.name, serverEnvironmentName);
|
|
1480
1498
|
emitEncryptionKey = true;
|
|
1481
1499
|
const normalizedPath = normalizeRelativePath(path.relative(path.join(chunk.fileName, ".."), KEY_FILE));
|
|
1482
1500
|
const replacement = `import(${JSON.stringify(normalizedPath)}).then(__m => __m.default)`;
|
|
@@ -1485,7 +1503,7 @@ function vitePluginDefineEncryptionKey(useServerPluginOptions) {
|
|
|
1485
1503
|
}
|
|
1486
1504
|
},
|
|
1487
1505
|
writeBundle() {
|
|
1488
|
-
if (this.environment.name ===
|
|
1506
|
+
if (this.environment.name === serverEnvironmentName && emitEncryptionKey) fs.writeFileSync(path.join(this.environment.config.build.outDir, KEY_FILE), `export default ${defineEncryptionKey};\n`);
|
|
1489
1507
|
}
|
|
1490
1508
|
}];
|
|
1491
1509
|
}
|
|
@@ -1961,4 +1979,4 @@ function __vite_rsc_wrap_css__(value, name) {
|
|
|
1961
1979
|
}
|
|
1962
1980
|
|
|
1963
1981
|
//#endregion
|
|
1964
|
-
export { transformHoistInlineDirective, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
|
|
1982
|
+
export { getPluginApi, transformHoistInlineDirective, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-
|
|
2
|
-
export { AssetDeps, AssetsManifest, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, transformRscCssExport, vitePluginRscMinimal };
|
|
1
|
+
import { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-BFcMxUSS.js";
|
|
2
|
+
export { AssetDeps, AssetsManifest, PluginApi, ResolvedAssetDeps, ResolvedAssetsManifest, RscPluginManager, RscPluginOptions, vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
|
package/dist/plugin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./dist-DiJnRA1C.js";
|
|
2
2
|
import "./plugin-CZbI4rhS.js";
|
|
3
|
-
import { transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-
|
|
3
|
+
import { getPluginApi, transformRscCssExport, vitePluginRsc, vitePluginRscMinimal } from "./plugin-iKgvucKS.js";
|
|
4
4
|
import "./encryption-utils-BDwwcMVT.js";
|
|
5
5
|
import "./rpc-tGuLT8PD.js";
|
|
6
6
|
import "./shared-BWHxNw3Q.js";
|
|
7
7
|
|
|
8
|
-
export { vitePluginRsc as default, transformRscCssExport, vitePluginRscMinimal };
|
|
8
|
+
export { vitePluginRsc as default, getPluginApi, transformRscCssExport, vitePluginRscMinimal };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/plugin-rsc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.28",
|
|
4
4
|
"description": "React Server Components (RSC) support for Vite.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"@tsconfig/strictest": "^2.0.5",
|
|
53
53
|
"@types/estree": "^1.0.8",
|
|
54
54
|
"@types/node": "^22.18.0",
|
|
55
|
-
"@types/react": "^19.1.
|
|
56
|
-
"@types/react-dom": "^19.1.
|
|
55
|
+
"@types/react": "^19.1.12",
|
|
56
|
+
"@types/react-dom": "^19.1.9",
|
|
57
57
|
"@vitejs/plugin-react": "workspace:*",
|
|
58
58
|
"react": "^19.1.1",
|
|
59
59
|
"react-dom": "^19.1.1",
|