Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
To automatically regenerate CSS (e.g. through a PostCSS pipeline) when files change, use a file watcher. The approach below works for any script you want to run on file changes.
Example: a script that builds CSS:
"scripts": {
"build:css": "postcss src/tailwind.css -o static/dist/tailwind.css",
}
To re-run it whenever files in the layouts folder change (e.g. to regenerate CSS and run purge/minification from your PostCSS setup), use the watch package.
Install it:
npm install watch
Add a watch script to package.json that runs build:css whenever the layouts folder changes:
"scripts": {
"build:css": "postcss src/tailwind.css -o static/dist/tailwind.css",
"watch": "watch 'npm run build:css' ./layouts"
}
Now run npm run watch or yarn watch.