Skip to content

Commit

Permalink
fix(plugins): enforce index.html transformation on "pre"
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Jul 21, 2024
1 parent 46aa239 commit 2254b3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-colts-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"stein-plugin-tailwindcss": patch
"stein-plugin-unocss": patch
---

Transform HTML before plugins hooks (support for virtual module resolution in build)
9 changes: 6 additions & 3 deletions plugins/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ export default definePlugin<Config>(() => {
}
}),

transformIndexHtml (html) {
const endHead = html.indexOf("</head>");
return html.slice(0, endHead) + `<script src="${TW_INJECT_ID}" type="module"></script>` + html.slice(endHead);
transformIndexHtml: {
order: "pre",
handler: (html) => {
const endHead = html.indexOf("</head>");
return html.slice(0, endHead) + `<script src="${TW_INJECT_ID}" type="module"></script>` + html.slice(endHead);
}
}
}
} satisfies Plugin;
Expand Down
9 changes: 6 additions & 3 deletions plugins/unocss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ export default definePlugin<Partial<Config>>((userConfiguration) => {
return injects.join('\n')
},

transformIndexHtml (html) {
const endHead = html.indexOf("</head>");
return html.slice(0, endHead) + `<script src="${UNO_INJECT_ID}" type="module"></script>` + html.slice(endHead);
transformIndexHtml: {
enforce: "pre",
handler: (html) => {
const endHead = html.indexOf("</head>");
return html.slice(0, endHead) + `<script src="${UNO_INJECT_ID}" type="module"></script>` + html.slice(endHead);
}
}
}
} satisfies Plugin;
Expand Down

0 comments on commit 2254b3b

Please sign in to comment.