Skip to content

Commit 8359228

Browse files
philipp-spiessthecrypticaceadamwathan
authored
Rework Vite plugin to support lightningcss pre processor and fast rebuilds (#14269)
Fixes #14205 Fixes #14106 This PR reworks the Vite extension in order to supprt `lightningcss` as the pre-processor, enable faster rebuilds, and adds support for `vite build --watch` mode. To make this change possible, we've done two major changes to the extension that have caused the other changes. ## 1. Tailwind CSS is a preprocessor We now run all of our modifications in `enforce: 'pre'`. This means that Tailwind CSS now gets the untransformed CSS files rather than the one already going through postcss or lightningcss. We do this because Tailwind CSS _is_ a preprocessor at the same level as those tools and we do sometimes use the language in ways that [creates problems when it's the input for other bundlers](#14269). The correct solution here is to make Tailwind not depend on any other transformations. The main reason we were not using the `enforce: 'pre'` phase in Vite before was becuase we relied on the `@import` flattening of postcss so we now have to do this manually. `@import` flattening is now a concern that every Tailwind V4 client has to deal with so this might actually be something we want to inline into tailwindcss in the future. ## 2. A Vite config can have multiple Tailwind roots This is something that we have not made very explicit in the previous iteration of the Vite plugin but we have to support multiple Tailwind roots in a single Vite workspace. A Tailwind root is a CSS file that is used to configure Tailwind. Technically, any CSS file can be the input for `tailwindcss` but you have to add certain rules (e.g. `@import "tailwindcss";`) to make the compiler do something. A workspace can have multiple of these rules (e.g. by having different Tailwind configures for different sub-pages). With the addition of [support for `@source` rules](#14078) and [JS config files](#14239), Tailwind roots become more complex and can have a custom list of _dependencies_ (that is other JavaScript modules the compiler includes as part of these new rules). In order to _only rebuild the roots we need to_, we have to make this separation very clear. --------- Co-authored-by: Jordan Pittman <[email protected]> Co-authored-by: Adam Wathan <[email protected]>
1 parent 390e2d3 commit 8359228

File tree

6 files changed

+742
-384
lines changed

6 files changed

+742
-384
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Add new standalone builds of Tailwind CSS v4 ([#14270](https://github.com/tailwindlabs/tailwindcss/pull/14270))
2424
- Support JavaScript configuration files using `@config` ([#14239](https://github.com/tailwindlabs/tailwindcss/pull/14239))
2525
- Support plugin options in `@plugin` ([#14264](https://github.com/tailwindlabs/tailwindcss/pull/14264))
26+
- Add support for using the Vite extension with `css.transformer` set to `lightningcss` ([#14269](https://github.com/tailwindlabs/tailwindcss/pull/14269))
2627

2728
### Fixed
2829

@@ -32,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3233
- Fix fallback values when using the CSS `theme()` function ([#14262](https://github.com/tailwindlabs/tailwindcss/pull/14262))
3334
- Fix support for declaration fallbacks in plugins ([#14265](https://github.com/tailwindlabs/tailwindcss/pull/14265))
3435
- Support bare values when using `tailwindcss/defaultTheme` ([#14257](https://github.com/tailwindlabs/tailwindcss/pull/14257))
36+
- Correctly update builds when using the Vite extension with `build --watch` ([#14269](https://github.com/tailwindlabs/tailwindcss/pull/14269))
3537

3638
### Changed
3739

integrations/utils.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dedent from 'dedent'
22
import fastGlob from 'fast-glob'
33
import killPort from 'kill-port'
4-
import { execSync, spawn } from 'node:child_process'
4+
import { exec, spawn } from 'node:child_process'
55
import fs from 'node:fs/promises'
66
import net from 'node:net'
77
import { homedir, platform, tmpdir } from 'node:os'
@@ -89,11 +89,23 @@ export function test(
8989
console.log(`> cd ${relative}`)
9090
}
9191
if (debug) console.log(`> ${command}`)
92-
return execSync(command, {
93-
cwd,
94-
stdio: 'pipe',
95-
...childProcessOptions,
96-
}).toString()
92+
return new Promise((resolve, reject) => {
93+
exec(
94+
command,
95+
{
96+
cwd,
97+
...childProcessOptions,
98+
},
99+
(error, stdout, stderr) => {
100+
if (error) {
101+
console.error(stderr)
102+
reject(error)
103+
} else {
104+
resolve(stdout.toString())
105+
}
106+
},
107+
)
108+
})
97109
},
98110
async spawn(command: string, childProcessOptions: ChildProcessOptions = {}) {
99111
let resolveDisposal: (() => void) | undefined

0 commit comments

Comments
 (0)