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

[Vite] TailwindCSS 2.2 JIT no longer tracks updated Svelte files #67

Closed
GrygrFlzr opened this issue Jun 19, 2021 · 8 comments
Closed

[Vite] TailwindCSS 2.2 JIT no longer tracks updated Svelte files #67

GrygrFlzr opened this issue Jun 19, 2021 · 8 comments
Assignees
Labels
adder:tailwindcss Relates to the Tailwind CSS adder confirmed bug Something isn't working upstream Can only be solved by an upstream project's changes

Comments

@GrygrFlzr
Copy link

Since 2.2 (tailwindlabs/tailwindcss#4514) the JIT engine switches to using the "tracking" context by default instead of "watching" context, which requires support in Vite. There's an issue about this filed at tailwindlabs/tailwindcss#4683 but I figure it's good to track this here as well.

Current workarounds:

  • Use TAILWIND_MODE=watch env var, which is ugly and not cross-platform without cross-env, and apparently doesn't trigger HMR
  • Start a separate tailwind process with npm-run-all
  • Downgrade tailwind to 2.1

Proper Fix:
vitejs/vite@6eaec3a should in theory fix this, although I can confirm that the CI failing tests on Windows is not a fluke, I can replicate it on my machine.

@maxmellen
Copy link

Can confirm I'm running into this issue as well.
The TAILWIND_MODE=watch trick is a lifesaver though 👍

@techniq
Copy link

techniq commented Jun 19, 2021

@GrygrFlzr Windows fix might have just been checked in - vitejs/vite@41b193c

@babichjacob babichjacob self-assigned this Jun 19, 2021
@babichjacob
Copy link
Member

babichjacob commented Jun 19, 2021

Putting

const mode = process.env.NODE_ENV;
const dev = mode === "development";
process.env.TAILWIND_MODE = dev ? "watch" : "build";

in svelte.config.js (or svelte.config.cjs for people using non-SvelteKit Vite) fixes it.

Use TAILWIND_MODE=watch env var, which is ugly and not cross-platform without cross-env, and apparently doesn't trigger HMR

Is that a Windows or WSL thing? I have always had working HMR (or at least what I think is HMR) with Tailwind JIT.

@babichjacob
Copy link
Member

Also note that due to svelte-add/tailwindcss#58, this project currently isn't able to produce a JIT Tailwind setup because svelte-add doesn't have an argument parser to detect that --jit is even being passed (and implementing this is harder than it sounds which is why it hasn't happened yet). An empty JIT config can be found here: https://github.com/svelte-add/tailwindcss/blob/76a390563f3b9d34938178b44c2b1a3c4f2d3eeb/__run.js#L38-L50

@babichjacob
Copy link
Member

Alternatively, sveltejs/kit#1715

@babichjacob babichjacob transferred this issue from svelte-add/tailwindcss Jun 21, 2021
@babichjacob babichjacob added adder:tailwindcss Relates to the Tailwind CSS adder confirmed bug Something isn't working upstream Can only be solved by an upstream project's changes labels Jun 21, 2021
@wiesson
Copy link

wiesson commented Jul 7, 2021

Putting

const mode = process.env.NODE_ENV;
const dev = mode === "development";
process.env.TAILWIND_MODE = dev ? "watch" : "build";

I just want to mention that with vite 2.4+, tw JIT does not properly work without the mentioned code above. (Freshly installed sveltekit example with tailwind)

@babichjacob
Copy link
Member

Putting

const mode = process.env.NODE_ENV;
const dev = mode === "development";
process.env.TAILWIND_MODE = dev ? "watch" : "build";

I just want to mention that with vite 2.4+, tw JIT does not properly work without the mentioned code above. (Freshly installed sveltekit example with tailwind)

svelte-add still includes this code for that reason

@wiesson
Copy link

wiesson commented Jul 7, 2021

Ah ok, I somehow assumed that vite 2.4 should fix it 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adder:tailwindcss Relates to the Tailwind CSS adder confirmed bug Something isn't working upstream Can only be solved by an upstream project's changes
Projects
None yet
Development

No branches or pull requests

5 participants