microsite
Version:
<br /> <br />
14 lines (13 loc) • 637 B
JavaScript
// This is an esbuild (?) bug where default exports are rewritten with a number appended
// so we'll just remove any trailing numbers
const cleanComponentName = (cmp) => cmp.replace(/[0-9]+$/, "");
export function generateHydrateScript(hydrateBindings, opts = {}) {
const { basePath = "/" } = opts;
const entries = Object.fromEntries(Object.entries(hydrateBindings)
.map(([file, exports]) => exports.map((cmp) => [
cleanComponentName(cmp),
[cmp, `${basePath}${file}`],
]))
.flat(1));
return `import init from "${basePath}_static/vendor/microsite.js";\ninit(${JSON.stringify(entries)})`;
}