Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Do not scan tailwind-merge sources for cadndidates
  • Loading branch information
philipp-spiess committed Jan 29, 2025
commit 0d9f07efda882a2c701611812e6007fca7682b69
14 changes: 14 additions & 0 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { Plugin, ResolvedConfig, Rollup, Update, ViteDevServer } from 'vite
const DEBUG = env.DEBUG
const SPECIAL_QUERY_RE = /[?&](raw|url)\b/

const IGNORED_DEPENDENCIES = ['tailwind-merge']

export default function tailwindcss(): Plugin[] {
let servers: ViteDevServer[] = []
let config: ResolvedConfig | null = null
Expand Down Expand Up @@ -62,6 +64,18 @@ export default function tailwindcss(): Plugin[] {
})

function scanFile(id: string, content: string, extension: string, isSSR: boolean) {
for (let dependency of IGNORED_DEPENDENCIES) {
// We validated that Vite IDs always use posix style path separators, even on Windows.
// In dev build, Vite precompiles dependencies
if (id.includes(`.vite/deps/${dependency}.js`)) {
return
}
// In prod builds, use the node_modules path
if (id.includes(`/node_modules/${dependency}/`)) {
return
}
}

let updated = false
for (let candidate of moduleGraphScanner.scanFiles([{ content, extension }])) {
updated = true
Expand Down
1 change: 1 addition & 0 deletions playgrounds/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@vitejs/plugin-react": "^4.3.4",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tailwind-merge": "^2.6.0",
"tailwindcss": "workspace:^"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion playgrounds/vite/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { twMerge } from 'tailwind-merge'

export function App() {
return (
<div className="m-3 p-3 border">
<h1 className="text-blue-500">Hello World</h1>
<h1 className={twMerge('text-red-500', 'text-blue-500')}>Hello World</h1>
<div className="-inset-x-full -inset-y-full -space-x-full -space-y-full -inset-full"></div>
</div>
)
Expand Down
20 changes: 14 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.