Skip to content

Commit

Permalink
feat: generate src/tailwind.css when not exists, Close #42
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Nov 27, 2024
1 parent 19d7e12 commit 6fa704f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-balloons-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@umijs/tnf': patch
---

feat: generate src/tailwind.css when not exists
18 changes: 11 additions & 7 deletions src/sync/write_tailwindcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,26 @@ export async function writeTailwindcss({
output: path.join(tmpPath, 'tailwindcss/tailwind.css'),
config: path.join(cwd, 'tailwind.config.js'),
};

// Enable tailwindcss only if the config file exists
if (!fs.existsSync(paths.config)) {
return;
}

// Generate input file if it doesn't exist
if (!fs.existsSync(paths.input)) {
logger.error(
`\`src/tailwind.css\` is missing when using tailwindcss. Please create it.
example:
fs.ensureDirSync(path.dirname(paths.input));
fs.writeFileSync(
paths.input,
`
@tailwind base;
@tailwind components;
@tailwind utilities;
`,
`.trimStart(),
);
logger.info(
`Created \`src/tailwind.css\` file. Please customize it before using tailwindcss.`,
);
return;
}

await generateFile({
Expand Down

0 comments on commit 6fa704f

Please sign in to comment.