-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not scan
tailwind-merge
sources for candidates (#16005)
Resolves #15722 This PR adds a list of ignored dependencies (in the current form only `tailwind-merge`) to the Vite extension which, when included in the dependency tree, are no longer scanned by the Tailwind CSS compiler for candidates. This is to work around an issue where some dependencies contain vast lists of valid Tailwind CSS class names which would otherwise always be inlined in the build. ## Test plan This was tested in our Vite playground on both dev and prod builds across macOS and Windows: ### Windows prod build before ![telegram-cloud-photo-size-4-5823632138052944949-y](https://github.com/user-attachments/assets/a2bca1c7-cef3-4f04-a588-cbf1afdbdd37) ### Windows prod build after This includes a debug `console.log(…)` to make sure it matches the right module. ![telegram-cloud-photo-size-4-5823632138052944951-y](https://github.com/user-attachments/assets/109b82c5-1946-4d44-b812-d68474686eb7) ### Windows dev build after This includes a debug `console.log(…)` to make sure it matches the right module. ![telegram-cloud-photo-size-4-5823632138052944948-y](https://github.com/user-attachments/assets/41cbe7f1-f997-4c6c-b5fe-01d574f7a999)
- Loading branch information
1 parent
9fef2bd
commit a4761ea
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { candidate, css, fetchStyles, html, js, retryAssertion, test, ts, txt } from '../utils' | ||
|
||
const WORKSPACE = { | ||
fs: { | ||
'package.json': txt` | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"tailwind-merge": "^2", | ||
"@tailwindcss/vite": "workspace:^", | ||
"tailwindcss": "workspace:^" | ||
}, | ||
"devDependencies": { | ||
"vite": "^6" | ||
} | ||
} | ||
`, | ||
'vite.config.ts': ts` | ||
import tailwindcss from '@tailwindcss/vite' | ||
import { defineConfig } from 'vite' | ||
export default defineConfig({ | ||
build: { cssMinify: false }, | ||
plugins: [tailwindcss()], | ||
}) | ||
`, | ||
'index.html': html` | ||
<head> | ||
<link rel="stylesheet" href="./src/index.css" /> | ||
<script type="module" src="./src/index.js"></script> | ||
</head> | ||
`, | ||
'src/index.js': js` | ||
import { twMerge } from 'tailwind-merge' | ||
twMerge('underline') | ||
console.log('underline') | ||
`, | ||
'src/index.css': css`@import 'tailwindcss/utilities' layer(utilities);`, | ||
}, | ||
} | ||
|
||
test( | ||
'does not scan tailwind-merge in production builds', | ||
WORKSPACE, | ||
async ({ fs, exec, expect }) => { | ||
await exec('pnpm vite build') | ||
|
||
let files = await fs.glob('dist/**/*.css') | ||
expect(files).toHaveLength(1) | ||
let [, content] = files[0] | ||
|
||
expect(content).toMatchInlineSnapshot(` | ||
"@layer utilities { | ||
.underline { | ||
text-decoration-line: underline; | ||
} | ||
} | ||
" | ||
`) | ||
}, | ||
) | ||
|
||
test('does not scan tailwind-merge in dev builds', WORKSPACE, async ({ spawn, expect }) => { | ||
let process = await spawn('pnpm vite dev') | ||
await process.onStdout((m) => m.includes('ready in')) | ||
|
||
let url = '' | ||
await process.onStdout((m) => { | ||
let match = /Local:\s*(http.*)\//.exec(m) | ||
if (match) url = match[1] | ||
return Boolean(url) | ||
}) | ||
|
||
await retryAssertion(async () => { | ||
let styles = await fetchStyles(url, '/index.html') | ||
|
||
expect(styles).not.toContain(candidate`flex`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters