From bf354bd3d0999f8320658740c21261204243a0b2 Mon Sep 17 00:00:00 2001 From: huseeiin Date: Sun, 22 Feb 2026 11:30:08 +0300 Subject: [PATCH 1/2] import manifest instead of reading it --- examples/ssr/stream/index.js | 6 +-- examples/ssr/stream/rollup.config.js | 62 ++++++++++++++-------------- examples/ssr/string/index.js | 5 +-- examples/ssr/string/rollup.config.js | 21 +++++++++- 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/examples/ssr/stream/index.js b/examples/ssr/stream/index.js index 726e3bbc..c9c94427 100644 --- a/examples/ssr/stream/index.js +++ b/examples/ssr/stream/index.js @@ -4,11 +4,7 @@ import { readFileSync } from "fs"; import { renderToStream } from "@solidjs/web"; import App from "../shared/src/components/App"; - -const manifest = JSON.parse( - readFileSync(new URL("../public/js/asset-manifest.json", import.meta.url), "utf-8") -); - +import manifest from "virtual:asset-manifest"; const app = express(); const port = 3000; diff --git a/examples/ssr/stream/rollup.config.js b/examples/ssr/stream/rollup.config.js index 7a65bc03..6c0c4885 100644 --- a/examples/ssr/stream/rollup.config.js +++ b/examples/ssr/stream/rollup.config.js @@ -1,10 +1,12 @@ import path from "path"; +import fs from "fs"; import nodeResolve from "@rollup/plugin-node-resolve"; import common from "@rollup/plugin-commonjs"; import babel from "@rollup/plugin-babel"; import copy from "rollup-plugin-copy"; const componentsDir = path.resolve("shared/src/components"); +const manifestPath = path.resolve("stream/public/js/asset-manifest.json"); function solidAssetManifest() { return { @@ -40,51 +42,51 @@ function solidAssetManifest() { }; } +function virtualAssetManifest() { + const VIRTUAL_ID = "virtual:asset-manifest"; + const RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_ID; + return { + name: "virtual-asset-manifest", + resolveId(id) { + if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID; + }, + load(id) { + if (id !== RESOLVED_VIRTUAL_ID) return; + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8")); + return `export default ${JSON.stringify(manifest, null, 2)}`; + } + }; +} + export default [ { - input: "./stream/index.js", + input: "shared/src/index.js", + output: [{ dir: "stream/public/js", format: "esm" }], preserveEntrySignatures: false, - output: [ - { - dir: "stream/lib", - format: "esm" - } - ], - external: ["solid-js", "@solidjs/web", "path", "express", "fs", "url"], plugins: [ - nodeResolve({ preferBuiltins: true, exportConditions: ["solid", "node"] }), + nodeResolve({ exportConditions: ["solid"] }), babel({ babelHelpers: "bundled", - presets: [["solid", { generate: "ssr", hydratable: true }]] + presets: [["solid", { generate: "dom", hydratable: true }]] }), - common() + common(), + solidAssetManifest(), + copy({ targets: [{ src: ["shared/static/*"], dest: "stream/public" }] }) ] }, { - input: "shared/src/index.js", - output: [ - { - dir: "stream/public/js", - format: "esm" - } - ], + input: "./stream/index.js", preserveEntrySignatures: false, + output: [{ dir: "stream/lib", format: "esm" }], + external: ["solid-js", "@solidjs/web", "path", "express", "fs", "url"], plugins: [ - nodeResolve({ exportConditions: ["solid"] }), + virtualAssetManifest(), + nodeResolve({ preferBuiltins: true, exportConditions: ["solid", "node"] }), babel({ babelHelpers: "bundled", - presets: [["solid", { generate: "dom", hydratable: true }]] + presets: [["solid", { generate: "ssr", hydratable: true }]] }), - common(), - solidAssetManifest(), - copy({ - targets: [ - { - src: ["shared/static/*"], - dest: "stream/public" - } - ] - }) + common() ] } ]; diff --git a/examples/ssr/string/index.js b/examples/ssr/string/index.js index 63b0f020..3c4634b5 100644 --- a/examples/ssr/string/index.js +++ b/examples/ssr/string/index.js @@ -1,13 +1,10 @@ import express from "express"; import url from "url"; -import { readFileSync } from "fs"; import { renderToString } from "@solidjs/web"; import App from "../shared/src/components/App"; -const manifest = JSON.parse( - readFileSync(new URL("../public/js/asset-manifest.json", import.meta.url), "utf-8") -); +import manifest from "virtual:asset-manifest"; const app = express(); const port = 3000; diff --git a/examples/ssr/string/rollup.config.js b/examples/ssr/string/rollup.config.js index 8474191f..d5661bf2 100644 --- a/examples/ssr/string/rollup.config.js +++ b/examples/ssr/string/rollup.config.js @@ -3,8 +3,10 @@ import nodeResolve from "@rollup/plugin-node-resolve"; import common from "@rollup/plugin-commonjs"; import babel from "@rollup/plugin-babel"; import copy from "rollup-plugin-copy"; +import fs from "fs"; const componentsDir = path.resolve("shared/src/components"); +const manifestPath = path.resolve("stream/public/js/asset-manifest.json"); function solidAssetManifest() { return { @@ -40,6 +42,22 @@ function solidAssetManifest() { }; } +function virtualAssetManifest() { + const VIRTUAL_ID = "virtual:asset-manifest"; + const RESOLVED_VIRTUAL_ID = "\0" + VIRTUAL_ID; + return { + name: "virtual-asset-manifest", + resolveId(id) { + if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID; + }, + load(id) { + if (id !== RESOLVED_VIRTUAL_ID) return; + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8")); + return `export default ${JSON.stringify(manifest, null, 2)}`; + } + }; +} + export default [ { input: "./string/index.js", @@ -56,7 +74,8 @@ export default [ babelHelpers: "bundled", presets: [["solid", { generate: "ssr", hydratable: true }]] }), - common() + common(), + virtualAssetManifest() ], preserveEntrySignatures: false }, From e0d5d959bc9e0e03163bd8cb5aa50e9c59afa0e8 Mon Sep 17 00:00:00 2001 From: huseeiin Date: Sun, 22 Feb 2026 12:25:59 +0300 Subject: [PATCH 2/2] fix --- examples/ssr/string/rollup.config.js | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/ssr/string/rollup.config.js b/examples/ssr/string/rollup.config.js index d5661bf2..62a59846 100644 --- a/examples/ssr/string/rollup.config.js +++ b/examples/ssr/string/rollup.config.js @@ -6,7 +6,7 @@ import copy from "rollup-plugin-copy"; import fs from "fs"; const componentsDir = path.resolve("shared/src/components"); -const manifestPath = path.resolve("stream/public/js/asset-manifest.json"); +const manifestPath = path.resolve("string/public/js/asset-manifest.json"); function solidAssetManifest() { return { @@ -28,17 +28,17 @@ function solidAssetManifest() { if (chunk.isEntry) entry.isEntry = true; if (chunk.isDynamicEntry) entry.isDynamicEntry = true; const imports = chunk.imports - .filter(imp => chunkKeyByFileName[imp]) - .map(imp => chunkKeyByFileName[imp]); + .filter((imp) => chunkKeyByFileName[imp]) + .map((imp) => chunkKeyByFileName[imp]); if (imports.length) entry.imports = imports; manifest[rel] = entry; } this.emitFile({ type: "asset", fileName: "asset-manifest.json", - source: JSON.stringify(manifest, null, 2) + source: JSON.stringify(manifest, null, 2), }); - } + }, }; } @@ -54,7 +54,7 @@ function virtualAssetManifest() { if (id !== RESOLVED_VIRTUAL_ID) return; const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8")); return `export default ${JSON.stringify(manifest, null, 2)}`; - } + }, }; } @@ -64,35 +64,35 @@ export default [ output: [ { dir: "string/lib", - format: "esm" - } + format: "esm", + }, ], external: ["solid-js", "@solidjs/web", "path", "express", "fs", "url"], plugins: [ nodeResolve({ preferBuiltins: true, exportConditions: ["solid", "node"] }), babel({ babelHelpers: "bundled", - presets: [["solid", { generate: "ssr", hydratable: true }]] + presets: [["solid", { generate: "ssr", hydratable: true }]], }), common(), - virtualAssetManifest() + virtualAssetManifest(), ], - preserveEntrySignatures: false + preserveEntrySignatures: false, }, { input: "shared/src/index.js", output: [ { dir: "string/public/js", - format: "esm" - } + format: "esm", + }, ], preserveEntrySignatures: false, plugins: [ nodeResolve({ exportConditions: ["solid"] }), babel({ babelHelpers: "bundled", - presets: [["solid", { generate: "dom", hydratable: true }]] + presets: [["solid", { generate: "dom", hydratable: true }]], }), common(), solidAssetManifest(), @@ -100,10 +100,10 @@ export default [ targets: [ { src: ["shared/static/*"], - dest: "string/public" - } - ] - }) - ] - } + dest: "string/public", + }, + ], + }), + ], + }, ];