Skip to content

Commit 5040fb1

Browse files
Cleanups
1 parent b54b270 commit 5040fb1

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

integrations/vite/solidstart.test.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { expect } from 'vitest'
2+
import { candidate, html, json, test, ts } from '../utils'
3+
4+
test(
5+
'production build',
6+
{
7+
fs: {
8+
'package.json': json`
9+
{
10+
"type": "module",
11+
"dependencies": {
12+
"vue": "^3.4.37",
13+
"tailwindcss": "workspace:^"
14+
},
15+
"devDependencies": {
16+
"@vitejs/plugin-vue": "^5.1.2",
17+
"@tailwindcss/vite": "workspace:^",
18+
"vite": "^5.3.5"
19+
}
20+
}
21+
`,
22+
'vite.config.ts': ts`
23+
import { defineConfig } from 'vite'
24+
import vue from '@vitejs/plugin-vue'
25+
import tailwindcss from '@tailwindcss/vite'
26+
27+
export default defineConfig({
28+
plugins: [vue(), tailwindcss()],
29+
})
30+
`,
31+
'index.html': html`
32+
<!doctype html>
33+
<html>
34+
<body>
35+
<div id="app"></div>
36+
<script type="module" src="./src/main.ts"></script>
37+
</body>
38+
</html>
39+
`,
40+
'src/main.ts': ts`
41+
import { createApp } from 'vue'
42+
import App from './App.vue'
43+
44+
createApp(App).mount('#app')
45+
`,
46+
'src/App.vue': html`
47+
<style>
48+
@import 'tailwindcss/utilities';
49+
@import 'tailwindcss/theme' theme(reference);
50+
.foo {
51+
@apply text-red-500;
52+
}
53+
</style>
54+
55+
<template>
56+
<div class="underline foo">Hello Vue!</div>
57+
</template>
58+
`,
59+
},
60+
},
61+
async ({ fs, exec }) => {
62+
await exec('pnpm vite build')
63+
64+
let files = await fs.glob('dist/**/*.css')
65+
expect(files).toHaveLength(1)
66+
67+
await fs.expectFileToContain(files[0][0], [candidate`underline`, candidate`foo`])
68+
},
69+
)

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

+6-14
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ export default function tailwindcss(): Plugin[] {
2626

2727
let roots: Map<string, Root> = new Map()
2828

29-
// Since new roots can be added at any time, we need to keep track of every
30-
// potential candidate file that was referenced before a root was created. To
31-
// save memory, this will store the path so we can read the latest version
32-
// from the disk and don't need to keep it in memory.
33-
let candidatePaths = new Set<string>()
34-
3529
// The Vite extension has two types of sources for candidates:
3630
//
3731
// 1. The module graph: These are all modules that vite transforms and we want
@@ -182,13 +176,6 @@ export default function tailwindcss(): Plugin[] {
182176
this.candidates.add(candidate)
183177
}
184178

185-
// Seed the candidate cache with candidates from all known candidate paths
186-
for (let candidate of this.scanner.scanFiles(
187-
[...candidatePaths.values()].map((path) => ({ file: path, extension: getExtension(path) })),
188-
)) {
189-
this.candidates.add(candidate)
190-
}
191-
192179
// Watch individual files found via custom `@source` paths
193180
for (let file of this.scanner.files) {
194181
addWatchFile(file)
@@ -354,6 +341,7 @@ export default function tailwindcss(): Plugin[] {
354341
async transform(src, id, options) {
355342
if (!isPotentialCssRootFile(id)) return
356343

344+
// TODO: Use DefaultMap
357345
let root = roots.get(id)
358346
if (!root) {
359347
root = new Root(id)
@@ -392,6 +380,7 @@ export default function tailwindcss(): Plugin[] {
392380
async transform(src, id) {
393381
if (!isPotentialCssRootFile(id)) return
394382

383+
// TODO: Use DefaultMap
395384
let root = roots.get(id)
396385
if (!root) {
397386
root = new Root(id)
@@ -459,7 +448,10 @@ function isCssRootFile(content: string) {
459448
content.includes('@tailwind') ||
460449
content.includes('@config') ||
461450
content.includes('@plugin') ||
462-
content.includes('@apply')
451+
content.includes('@apply') ||
452+
content.includes('@theme') ||
453+
content.includes('@variant') ||
454+
content.includes('@utility')
463455
)
464456
}
465457

0 commit comments

Comments
 (0)