Skip to content

Commit 3c373e2

Browse files
thecrypticaceRobinMalfait
authored andcommitted
Store candidates per-module
1 parent b19a0e8 commit 3c373e2

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

packages/@tailwindcss-vite/src/index.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function tailwindcss(): Plugin[] {
3535
// Note: To improve performance, we do not remove candidates from this set.
3636
// This means a longer-ongoing dev mode session might contain candidates that
3737
// are no longer referenced in code.
38-
let moduleGraphCandidates = new Set<string>()
38+
let moduleGraphCandidates = new DefaultMap<string, Set<string>>(() => new Set<string>())
3939
let moduleGraphScanner = new Scanner({})
4040

4141
let roots: DefaultMap<string, Root> = new DefaultMap(
@@ -46,7 +46,7 @@ export default function tailwindcss(): Plugin[] {
4646
let updated = false
4747
for (let candidate of moduleGraphScanner.scanFiles([{ content, extension }])) {
4848
updated = true
49-
moduleGraphCandidates.add(candidate)
49+
moduleGraphCandidates.get(id).add(candidate)
5050
}
5151

5252
if (updated) {
@@ -348,14 +348,9 @@ class Root {
348348
// root.
349349
private dependencies = new Set<string>()
350350

351-
// Whether to include candidates from the module graph. This is disabled when
352-
// the user provides `source(none)` to essentially disable auto source
353-
// detection.
354-
private includeCandidatesFromModuleGraph = true
355-
356351
constructor(
357352
private id: string,
358-
private getSharedCandidates: () => Set<string>,
353+
private getSharedCandidates: () => Map<string, Set<string>>,
359354
private base: string,
360355
) {}
361356

@@ -387,20 +382,14 @@ class Root {
387382
let sources = (() => {
388383
// Disable auto source detection
389384
if (this.compiler.root === 'none') {
390-
this.includeCandidatesFromModuleGraph = false
391385
return []
392386
}
393387

394388
// No root specified, use the module graph
395389
if (this.compiler.root === null) {
396-
this.includeCandidatesFromModuleGraph = true
397-
398390
return []
399391
}
400392

401-
// TODO: In a follow up PR we want this filter this against the module graph.
402-
this.includeCandidatesFromModuleGraph = true
403-
404393
// Use the specified root
405394
return [this.compiler.root]
406395
})().concat(this.compiler.globs)
@@ -440,13 +429,24 @@ class Root {
440429
this.requiresRebuild = true
441430

442431
env.DEBUG && console.time('[@tailwindcss/vite] Build CSS')
443-
let result = this.compiler.build(
444-
this.includeCandidatesFromModuleGraph
445-
? [...this.getSharedCandidates(), ...this.candidates]
446-
: Array.from(this.candidates),
447-
)
432+
let result = this.compiler.build([...this.sharedCandidates(), ...this.candidates])
448433
env.DEBUG && console.timeEnd('[@tailwindcss/vite] Build CSS')
449434

450435
return result
451436
}
437+
438+
private sharedCandidates(): Set<string> {
439+
if (!this.compiler) return new Set()
440+
if (this.compiler.root === 'none') return new Set()
441+
442+
let shared = new Set<string>()
443+
444+
for (let [id, candidates] of this.getSharedCandidates()) {
445+
for (let candidate of candidates) {
446+
shared.add(candidate)
447+
}
448+
}
449+
450+
return shared
451+
}
452452
}

0 commit comments

Comments
 (0)