feat(islands): serve the island runtime in dev, prod, and static builds
Adds /__wrnexus/islands.js (the bootstrap) and the /__wrnexus/island/ prefix (mount runtime, island bundles, shared chunks) to all three serving paths. Dev reuses the browserArtifactPaths registry pattern from pipeline.ts. Prod mirrors the clientModulesDir handler, including its filename allowlist, so island names cannot escape the output directory. The bootstrap is inert without a data-wrn-island marker, so island-free pages still download nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* The island bootstrap served at `/__wrnexus/islands.js`.
|
||||
*
|
||||
* Mirrors the `@wrnexus/csr` pattern: this file is only ever fetched when a
|
||||
* `data-wrn-island` marker is present, so island-free pages download nothing —
|
||||
* including React.
|
||||
*/
|
||||
export function getIslandRuntime(development = false): string {
|
||||
return `
|
||||
(function () {
|
||||
function loader(name) {
|
||||
return import("/__wrnexus/island/" + encodeURIComponent(name) + ".js");
|
||||
}
|
||||
|
||||
function boot() {
|
||||
if (!document.querySelector("[data-wrn-island]")) return;
|
||||
import("/__wrnexus/island/runtime.js").then(function (runtime) {
|
||||
runtime.mountIslands(document, { loader: loader, development: ${development} });
|
||||
window.__wrnexusUnmountIslands = function (root) {
|
||||
runtime.unmountIslands(root || document);
|
||||
};
|
||||
window.__wrnexusRemountIslands = function (root) {
|
||||
return runtime.remountIslands(root || document, {
|
||||
loader: loader,
|
||||
development: ${development}
|
||||
});
|
||||
};
|
||||
}).catch(function (error) {
|
||||
console.error("[wrnexus] failed to load the island runtime", error);
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", boot);
|
||||
} else {
|
||||
boot();
|
||||
}
|
||||
})();
|
||||
`;
|
||||
}
|
||||
Reference in New Issue
Block a user