Update 1: include
livereload
to refresh browser automatically on change
Update 2: clear express cache on each request instead of restarting on change
Update 3: explain reasons for livereload settings and also the double build
Put your tailwind.css directives file in root /styles folder. The css:build
script will generate /app/styles/tailwind.css.
Reference the generated CSS from root.tsx using import tailwind from 'url:./styles/tailwind.css'
NOTE: If you update to Tailwind CSS v2.1+, it has built-in JIT support. Just add mode: 'jit'
to your config.
Add LiveReload
to your pm2.config. You can update the wait time as needed to allow Remix/Tailwind to complete its build.
Import the <LiveReload/>
component in root.tsx. This will add the required <script/>
tag in development.
Update server.js to clear require cache on each request. Only restart express if server.js changes.
I added comments to my livereload (pm2.config) settings.
You may see Remix build multiple times when saving a file. It watches for changes, so when you save a route file, it will start the rebuild. But Tailwind JIT also watches files and will regenerate the css file, which remix also sees and that causes remix to rebuild. It would be nice if we could tell Remix to wait a bit before starting a rebuild, but with esbuild, it is so fast, it probably wouldn't make much difference.
Can you please explain why you have
-x css
in the livereload command?