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]);})`;
|
||||
|
||||
if (!fs.existsSync("./public/.output")) fs.mkdirSync("./public/.output");
|
||||
fs.writeFileSync(
|
||||
"./public/.output/registry.js",
|
||||
[...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(getPath("/404.html"));
|
||||
|
||||
// insert registry to head
|
||||
html = html
|
||||
.toString()
|
||||
.replace(
|
||||
"</head>",
|
||||
'<script type="module" src="./.output/registry.js"></script></head>'
|
||||
);
|
||||
// temporary; use ultrahtml later
|
||||
const registryScript =
|
||||
'<script type="module" src="./.output/registry.js"></script>';
|
||||
html = html.toString().replace("</head>", registryScript + "</head>");
|
||||
|
||||
return html ?? new Response("Not found", { status: 404 });
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue