Files
chandra/host/src/loader-web.mjs
T
2026-11-24 23:51:26 +00:00

17 lines
743 B
JavaScript

/** Loader for browsers: fetches the jco output under <base>/build/. */
export function webLoader(base) {
return async (name) => {
const r = await fetch(`${base}/build/components/${name}.meta.json`);
if (!r.ok) throw new Error(`cannot load ${name}.meta.json: HTTP ${r.status}`);
const meta = await r.json();
const dir = `${base}/build/jco/${name}`;
const mod = await import(`${dir}/${name}.js`);
const getCoreModule = async (p) => {
const res = await fetch(`${dir}/${p}`);
if (!res.ok) throw new Error(`cannot fetch ${p}: HTTP ${res.status}`);
return WebAssembly.compile(await res.arrayBuffer());
};
return { meta, instantiate: (imports) => mod.instantiate(getCoreModule, imports) };
};
}