Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions examples/ssr/stream/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
62 changes: 32 additions & 30 deletions examples/ssr/stream/rollup.config.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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()
]
}
];
5 changes: 1 addition & 4 deletions examples/ssr/string/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
55 changes: 37 additions & 18 deletions examples/ssr/string/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("string/public/js/asset-manifest.json");

function solidAssetManifest() {
return {
Expand All @@ -26,17 +28,33 @@ 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),
});
}
},
};
}

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)}`;
},
};
}

Expand All @@ -46,45 +64,46 @@ 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()
common(),
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(),
copy({
targets: [
{
src: ["shared/static/*"],
dest: "string/public"
}
]
})
]
}
dest: "string/public",
},
],
}),
],
},
];