fix: tailwind don't magically add content regex (#2060)
This commit is contained in:
+26
-33
@@ -9,17 +9,8 @@ async function initTailwind(
|
|||||||
config: ResolvedFreshConfig,
|
config: ResolvedFreshConfig,
|
||||||
): Promise<postcss.Processor> {
|
): Promise<postcss.Processor> {
|
||||||
const root = path.dirname(config.staticDir);
|
const root = path.dirname(config.staticDir);
|
||||||
let relativeRoot = "";
|
|
||||||
if (root !== Deno.cwd()) {
|
|
||||||
relativeRoot = path.relative(Deno.cwd(), root).split(path.sep).join("/") +
|
|
||||||
"/";
|
|
||||||
}
|
|
||||||
|
|
||||||
let tailwindConfig: Config = {
|
let tailwindConfig: Config | null = null;
|
||||||
content: [
|
|
||||||
`${relativeRoot}{routes,components,islands}/**/*.{ts,tsx,js,jsx,mjs,cjs}`,
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const configFilePaths = [
|
const configFilePaths = [
|
||||||
path.join(Deno.cwd(), "tailwind.config.ts"),
|
path.join(Deno.cwd(), "tailwind.config.ts"),
|
||||||
@@ -38,31 +29,33 @@ async function initTailwind(
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importedConfig === null) continue;
|
if (importedConfig !== null) {
|
||||||
importedConfig.content = importedConfig.content ?? [];
|
if (!Array.isArray(importedConfig.content)) {
|
||||||
|
throw new Error(`Expected tailwind "content" option to be an array`);
|
||||||
if (!Array.isArray(importedConfig.content)) {
|
|
||||||
throw new Error(`Expected tailwind "content" option to be an array`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const configContent = importedConfig.content.map((pattern) => {
|
|
||||||
if (typeof pattern === "string") {
|
|
||||||
return path.join(
|
|
||||||
path.relative(Deno.cwd(), path.dirname(configFile)),
|
|
||||||
pattern,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return pattern;
|
|
||||||
});
|
|
||||||
|
|
||||||
tailwindConfig = {
|
importedConfig.content = importedConfig.content.map((pattern) => {
|
||||||
...importedConfig,
|
if (typeof pattern === "string") {
|
||||||
content: [
|
return path.join(
|
||||||
...configContent,
|
path.relative(Deno.cwd(), path.dirname(configFile)),
|
||||||
...tailwindConfig.content as string[],
|
pattern,
|
||||||
],
|
);
|
||||||
};
|
}
|
||||||
break;
|
return pattern;
|
||||||
|
});
|
||||||
|
|
||||||
|
tailwindConfig = importedConfig;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tailwindConfig === null) {
|
||||||
|
throw new Error(
|
||||||
|
`Could not find tailwind config file. Searched the following locations:\n\n${
|
||||||
|
configFilePaths.map((p) => `- ${p}`).join("\n")
|
||||||
|
}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const plugins: postcss.AcceptedPlugin[] = [
|
const plugins: postcss.AcceptedPlugin[] = [
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { Config } from "tailwindcss";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
content: [
|
||||||
|
"{routes,islands,components}/**/*.{ts,tsx}",
|
||||||
|
],
|
||||||
|
} as Config;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { Config } from "tailwindcss";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
content: [
|
||||||
|
"{routes,islands,components}/**/*.{ts,tsx}",
|
||||||
|
],
|
||||||
|
} as Config;
|
||||||
Reference in New Issue
Block a user