Load Tailwind config

This commit is contained in:
Alex Gleason committed 2025-08-11 15:32:29 -07:00
1 parent 0cb6096019
commit 7eaa3f583f
2 files changed
+24 -21

No files matched your search

+8
View File
@@ -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
View File
@@ -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"
) ?? ""
);
}
}