Skip to content

Commit c94b5d2

Browse files
committed
Set the Tailwind config's preflight CSS to false
This resolves the problem: Error: ENOENT: no such file or directory, open '/var/task/node_modules/tailwindcss/lib/css/preflight.css' Also we will grab everything that comes after the first instance of .generated, so this will include things like hover, after, etc. as well. See https://stackoverflow.com/a/78399488/1134080
1 parent 10f9676 commit c94b5d2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pages/api/generate-css.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,28 @@ export default async function handler(
2323
`;
2424

2525
try {
26-
const result = await postcss([tailwindcss, autoprefixer])
26+
const result = await postcss([
27+
tailwindcss({
28+
config: { content: ["./*.none"], corePlugins: { preflight: false } },
29+
}),
30+
autoprefixer,
31+
])
2732
.process(css, { from: undefined })
2833
.then((result) => {
2934
let css = result.css;
30-
// Extract the part between ".generated {" and nearest "}" over multiple lines
31-
const generatedClasses = css.match(/\.generated \{([^}]*)\}/s);
32-
if (generatedClasses) {
33-
css = generatedClasses[1];
34-
// Trim all lines to remove extra spaces in beginning but keep new lines
35-
css = css.replace(/^[ \t]+/gm, "");
35+
36+
// Find ".generated" text and extract everything after it.
37+
const generatedIndex = css.indexOf(".generated");
38+
if (generatedIndex !== -1) {
39+
css = css.substring(generatedIndex);
3640
} else {
3741
css = "no: result;";
3842
}
43+
44+
// Format the CSS
45+
css = css.replace(/^\s+/gm, " ");
46+
css = css.replace(/^\s*\.generated/gm, ".generated");
47+
3948
return css;
4049
});
4150

0 commit comments

Comments
 (0)