mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Load Tailwind config
This commit is contained in:
1 parent
7d423c9829
commit
b3ce6979c4
2 files changed
+24
-21
No files matched your search
@@ -36,6 +36,14 @@ export function esmPlugin(packageLock: PackageLock, target?: string): Plugin {
|
||||
name: "esm",
|
||||
|
||||
setup(build) {
|
||||
// http(s) imports
|
||||
build.onResolve({ filter: /^https?:\/\// }, async (args) => {
|
||||
return {
|
||||
path: args.path,
|
||||
namespace: "esm",
|
||||
};
|
||||
});
|
||||
|
||||
// Handle bare imports like "react"
|
||||
build.onResolve({ filter: /^[^./].*/ }, (args) => {
|
||||
const packageName = args.path.startsWith("@")
|
||||
|
||||
+16
-21
@@ -36,7 +36,15 @@ export async function buildProject(
|
||||
const doc = domParser.parseFromString(indexHtmlText, "text/html");
|
||||
|
||||
const results = await esbuild.build({
|
||||
entryPoints: ["./main.tsx"],
|
||||
stdin: {
|
||||
contents: `
|
||||
import "@/main.tsx";
|
||||
import tailwindConfig from "@/../tailwind.config.ts";
|
||||
import "https://esm.sh/tailwindcss-cdn@3";
|
||||
tailwind.config = tailwindConfig;
|
||||
`,
|
||||
loader: "tsx",
|
||||
},
|
||||
bundle: true,
|
||||
write: false,
|
||||
format: "esm",
|
||||
@@ -53,7 +61,13 @@ export async function buildProject(
|
||||
|
||||
for (const file of results.outputFiles) {
|
||||
const relativePath = file.path.replace(/^\//, "");
|
||||
dist[relativePath] = file.contents;
|
||||
if (relativePath === "stdin.js") {
|
||||
dist["main.js"] = file.contents;
|
||||
} else if (relativePath === "stdin.css") {
|
||||
dist["main.css"] = file.contents;
|
||||
} else {
|
||||
dist[relativePath] = file.contents;
|
||||
}
|
||||
}
|
||||
|
||||
// Update index.html with proper script and link tags
|
||||
@@ -78,23 +92,4 @@ function updateIndexHtml(doc: Document): void {
|
||||
style.setAttribute("rel", "stylesheet");
|
||||
style.setAttribute("href", "/main.css");
|
||||
doc.head.appendChild(style);
|
||||
|
||||
const tailwindScript = doc.createElement("script");
|
||||
tailwindScript.setAttribute(
|
||||
"src",
|
||||
"https://esm.sh/@tailwindcss/browser@4",
|
||||
);
|
||||
tailwindScript.setAttribute("type", "module");
|
||||
doc.head.appendChild(tailwindScript);
|
||||
|
||||
const csp = doc.querySelector('meta[http-equiv="content-security-policy"]');
|
||||
if (csp) {
|
||||
csp.setAttribute(
|
||||
"content",
|
||||
csp.getAttribute("content")?.replace(
|
||||
"script-src 'self'",
|
||||
"script-src 'self' https://esm.sh"
|
||||
) ?? ""
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user