tailwindcss/integrations/vite
Philipp Spiess 15fc7f4558
Apply non-Tailwind CSS transforms in Vite plugin (#14871)
Fixes: #14839
Fixes: #14796

This PR fixes an issue in the Vite extension where we previously only
ran a small list of allow-listed plugins for the second stage transform
in the build step. This caused some CSS features to unexpectedly not
work in production builds (one such example is Vue's `:deep(...)`
selector).

To fix this, I changed the allow listed plugins that we do want to run
to a block list to filter out some plugins we know we don't want to run
(e.g. the Tailwind Vite plugin for example or some built-in Vite plugins
that are not necessary).


## Test plan

This PR adds a new integration test suite to test interop with a custom
Vite transformer that looks like this:

```js
{
  name: 'recolor',
  transform(code, id) {
    if (id.includes('.css')) {
      return code.replace(/red/g, 'blue')
    }
  },
}
```

I also validated that this does indeed fix the Vue `:deep(...)` selector
related issue that we were seeing by copying the repro of #14839 into
our playground:

![Screenshot 2024-11-05 at
13.35.26.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/0Y77ilPI2WoJfMLFiAEw/4e46ab61-4acf-461a-9e40-f7c9ec3c69b2.png)

You can see in the screenshot above that the `:deep()` selector
overwrites the scoped styles as expected in both the dev mode and the
prod build (screenshotted).

Furthermore I reproduced the issue reported in
https://github.com/tailwindlabs/tailwindcss/issues/14796 and was able to
confirm that in a production build, the styling works as expected:

<img width="517" alt="Screenshot 2024-11-06 at 14 26 50"
src="https://github.com/user-attachments/assets/ade6fe38-be0d-4bd0-9a9a-67b6fec05ae0">

Lastly, I created a repository out of the biggest known-to-me Vite
projects: [Astro, Nuxt, Remix, SolidStart, and
SvelteKit](https://github.com/philipp-spiess/tailwind-playgrounds) and
verified that both dev and prod builds show no issue and the candidate
list is properly appended in each case.

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
2024-11-07 16:26:18 +01:00
..
astro.test.ts Revert "Fix Astro integration test by pinning zod-to-json-schema" (#14792) 2024-10-25 11:31:34 +02:00
config.test.ts Integration tests: Move all file writes into retry block (#14350) 2024-09-06 10:48:49 +02:00
css-modules.test.ts Don't assert on mangled CSS names (#14397) 2024-09-11 17:37:36 +02:00
index.test.ts Remove fallbacks from theme var(...) calls (#14881) 2024-11-05 15:44:21 -05:00
multi-root.test.ts Add integration tests for multi-root builds (#14564) 2024-10-01 17:00:20 +02:00
nuxt.test.ts Apply non-Tailwind CSS transforms in Vite plugin (#14871) 2024-11-07 16:26:18 +01:00
other-transforms.test.ts Apply non-Tailwind CSS transforms in Vite plugin (#14871) 2024-11-07 16:26:18 +01:00
url-rewriting.test.ts Rewrite urls in CSS files when using Vite (#14877) 2024-11-07 09:51:58 -05:00
vue.test.ts Apply non-Tailwind CSS transforms in Vite plugin (#14871) 2024-11-07 16:26:18 +01:00