@ivogt/rsc-router 0.0.0-experimental.1 → 0.0.0-experimental.2
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/package.json +1 -1
- package/src/server/root-layout.tsx +1 -1
- package/src/vite/index.ts +79 -0
package/package.json
CHANGED
package/src/vite/index.ts
CHANGED
|
@@ -21,6 +21,39 @@ export { exposeLocationStateId } from "./expose-location-state-id.ts";
|
|
|
21
21
|
|
|
22
22
|
// Virtual module type declarations in ./version.d.ts
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Plugin to transform CJS react-server-dom vendor file to ESM.
|
|
26
|
+
* The @vitejs/plugin-rsc package ships client.browser.js as CommonJS
|
|
27
|
+
* which doesn't work in the browser. This transforms it to ESM re-exports.
|
|
28
|
+
*/
|
|
29
|
+
function createCjsToEsmPlugin(): Plugin {
|
|
30
|
+
return {
|
|
31
|
+
name: "rsc-router:cjs-to-esm",
|
|
32
|
+
enforce: "pre",
|
|
33
|
+
transform(code, id) {
|
|
34
|
+
// Transform the client.browser.js file from CJS to ESM
|
|
35
|
+
// Match any path containing vendor/react-server-dom/client.browser.js
|
|
36
|
+
if (
|
|
37
|
+
id.includes("vendor/react-server-dom/client.browser.js") ||
|
|
38
|
+
id.includes("vendor\\react-server-dom\\client.browser.js")
|
|
39
|
+
) {
|
|
40
|
+
// The original file uses: module.exports = require('./cjs/...')
|
|
41
|
+
// Transform to ESM re-export from the development or production CJS file
|
|
42
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
43
|
+
const cjsFile = isProd
|
|
44
|
+
? "./cjs/react-server-dom-webpack-client.browser.production.js"
|
|
45
|
+
: "./cjs/react-server-dom-webpack-client.browser.development.js";
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
code: `export * from "${cjsFile}";`,
|
|
49
|
+
map: null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
24
57
|
/**
|
|
25
58
|
* RSC plugin entry points configuration.
|
|
26
59
|
* All entries use virtual modules by default. Specify a path to use a custom entry file.
|
|
@@ -422,6 +455,27 @@ export async function rscRouter(
|
|
|
422
455
|
config() {
|
|
423
456
|
// Configure environments for cloudflare deployment
|
|
424
457
|
return {
|
|
458
|
+
resolve: {
|
|
459
|
+
alias: {
|
|
460
|
+
// Map rsc-router/* to @ivogt/rsc-router/* for virtual entries
|
|
461
|
+
// This allows the package to work when published under a scoped name
|
|
462
|
+
"rsc-router/internal/deps/browser":
|
|
463
|
+
"@ivogt/rsc-router/internal/deps/browser",
|
|
464
|
+
"rsc-router/internal/deps/ssr":
|
|
465
|
+
"@ivogt/rsc-router/internal/deps/ssr",
|
|
466
|
+
"rsc-router/internal/deps/rsc":
|
|
467
|
+
"@ivogt/rsc-router/internal/deps/rsc",
|
|
468
|
+
"rsc-router/internal/deps/html-stream-client":
|
|
469
|
+
"@ivogt/rsc-router/internal/deps/html-stream-client",
|
|
470
|
+
"rsc-router/internal/deps/html-stream-server":
|
|
471
|
+
"@ivogt/rsc-router/internal/deps/html-stream-server",
|
|
472
|
+
"rsc-router/browser": "@ivogt/rsc-router/browser",
|
|
473
|
+
"rsc-router/client": "@ivogt/rsc-router/client",
|
|
474
|
+
"rsc-router/server": "@ivogt/rsc-router/server",
|
|
475
|
+
"rsc-router/rsc": "@ivogt/rsc-router/rsc",
|
|
476
|
+
"rsc-router/ssr": "@ivogt/rsc-router/ssr",
|
|
477
|
+
},
|
|
478
|
+
},
|
|
425
479
|
environments: {
|
|
426
480
|
client: {
|
|
427
481
|
build: {
|
|
@@ -515,6 +569,27 @@ export async function rscRouter(
|
|
|
515
569
|
const useVirtualRSC = finalEntries.rsc === VIRTUAL_IDS.rsc;
|
|
516
570
|
|
|
517
571
|
return {
|
|
572
|
+
resolve: {
|
|
573
|
+
alias: {
|
|
574
|
+
// Map rsc-router/* to @ivogt/rsc-router/* for virtual entries
|
|
575
|
+
// This allows the package to work when published under a scoped name
|
|
576
|
+
"rsc-router/internal/deps/browser":
|
|
577
|
+
"@ivogt/rsc-router/internal/deps/browser",
|
|
578
|
+
"rsc-router/internal/deps/ssr":
|
|
579
|
+
"@ivogt/rsc-router/internal/deps/ssr",
|
|
580
|
+
"rsc-router/internal/deps/rsc":
|
|
581
|
+
"@ivogt/rsc-router/internal/deps/rsc",
|
|
582
|
+
"rsc-router/internal/deps/html-stream-client":
|
|
583
|
+
"@ivogt/rsc-router/internal/deps/html-stream-client",
|
|
584
|
+
"rsc-router/internal/deps/html-stream-server":
|
|
585
|
+
"@ivogt/rsc-router/internal/deps/html-stream-server",
|
|
586
|
+
"rsc-router/browser": "@ivogt/rsc-router/browser",
|
|
587
|
+
"rsc-router/client": "@ivogt/rsc-router/client",
|
|
588
|
+
"rsc-router/server": "@ivogt/rsc-router/server",
|
|
589
|
+
"rsc-router/rsc": "@ivogt/rsc-router/rsc",
|
|
590
|
+
"rsc-router/ssr": "@ivogt/rsc-router/ssr",
|
|
591
|
+
},
|
|
592
|
+
},
|
|
518
593
|
environments: {
|
|
519
594
|
client: {
|
|
520
595
|
build: {
|
|
@@ -603,6 +678,10 @@ export async function rscRouter(
|
|
|
603
678
|
plugins.push(createVersionInjectorPlugin(rscEntryPath));
|
|
604
679
|
}
|
|
605
680
|
|
|
681
|
+
// Add CJS-to-ESM transform for @vitejs/plugin-rsc vendor files
|
|
682
|
+
// This must be added to transform the CommonJS client.browser.js to ESM
|
|
683
|
+
plugins.push(createCjsToEsmPlugin());
|
|
684
|
+
|
|
606
685
|
return plugins;
|
|
607
686
|
}
|
|
608
687
|
|