17 lines
743 B
JavaScript
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) };
|
|
};
|
|
}
|