Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t cache .css files in Tailwind projects #3326

Merged
merged 1 commit into from May 20, 2021
Merged

Don’t cache .css files in Tailwind projects #3326

merged 1 commit into from May 20, 2021

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented May 20, 2021

Resolves #3041, #3246

Changes

2021-05-19.18-55-25.2021-05-19.18_55_59.mp4

Our dev server aggressively caches builds, which is good for HMR but is really hard for making Tailwind usable.

Problem

In the server, we can see that an .html or .js file changed, and send the necessary HMR response, either to reload the page, or clear the cache, or both. But with Tailwind, index.html is the file that changes, but global.css is the file that needs the HMR response / cache bust.

There’s currently no link between these files, at least as far as the dev server is aware. To fix this, we’d have to a) scan index.html contents and see, or b) build some dependency graph, or c) conditionally change caching behavior based on whether Tailwind is present or not.

This PR

In Tailwind projects only, .css files are not cached in the dev server. This lets Tailwind handle when they are rebuilt, and not Snowpack.

This PR adds a devOptions.tailwindConfig option to enable / disable Tailwind. This saves us from having to scan for Tailwind presence/absense and instead lets the user tell us.

Testing

Manually tested; not easy to write a test for this

Docs

Added devOptions.tailwindConfig as a config option, added docs.

@drwpow drwpow requested a review from a team as a code owner May 20, 2021 01:02
@vercel
Copy link

vercel bot commented May 20, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/AyRuZ8fJpxwaG8q14mgvPALrcFXQ
✅ Preview: https://snowpack-git-tailwind-pikapkg.vercel.app

@drwpow drwpow changed the title Don’t cache .css files in build Don’t cache .css files in dev May 20, 2021
@matthewp
Copy link
Contributor

I'm fine with this, will defer to @FredKSchott . It would be nice if we knew the project used Tailwind (check the package.json?) and conditionally apply this optimization. Not sure how practical that is.

@drwpow
Copy link
Collaborator Author

drwpow commented May 20, 2021

@matthewp good suggestion! Added a config option. Tested and still seems to be working. Now we only don’t cache if devOptions.tailwindConfig is set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Tailwind JIT Compiler don't rebuild stylesheet
2 participants