feat: initial auto insert of registry to head
This commit is contained in:
parent
325ecf36c6
commit
5dccd552cd
2 changed files with 5 additions and 7 deletions
|
@ -19,6 +19,7 @@ export default defineNitroPlugin(async () => {
|
||||||
|
|
||||||
const customElementsDefine = `Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})`;
|
const customElementsDefine = `Object.keys(registry).forEach((key) => {if(window?.hasOwnProperty("customElements"))customElements.define(key, registry[key]);})`;
|
||||||
|
|
||||||
|
if (!fs.existsSync("./public/.output")) fs.mkdirSync("./public/.output");
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
"./public/.output/registry.js",
|
"./public/.output/registry.js",
|
||||||
[...imports, registryObject, customElementsDefine].join(";")
|
[...imports, registryObject, customElementsDefine].join(";")
|
||||||
|
|
|
@ -10,13 +10,10 @@ export default eventHandler(async (event) => {
|
||||||
if (!html) html = await useStorage().getItem(fallback);
|
if (!html) html = await useStorage().getItem(fallback);
|
||||||
if (!html) html = await useStorage().getItem(getPath("/404.html"));
|
if (!html) html = await useStorage().getItem(getPath("/404.html"));
|
||||||
|
|
||||||
// insert registry to head
|
// temporary; use ultrahtml later
|
||||||
html = html
|
const registryScript =
|
||||||
.toString()
|
'<script type="module" src="./.output/registry.js"></script>';
|
||||||
.replace(
|
html = html.toString().replace("</head>", registryScript + "</head>");
|
||||||
"</head>",
|
|
||||||
'<script type="module" src="./.output/registry.js"></script></head>'
|
|
||||||
);
|
|
||||||
|
|
||||||
return html ?? new Response("Not found", { status: 404 });
|
return html ?? new Response("Not found", { status: 404 });
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue