Skip to content

Commit 1906991

Browse files
Revert "Fix Astro by adding the componentns folder instead of falling to full fs scanning"
This reverts commit daacc5e.
1 parent 7e5bdf7 commit 1906991

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

integrations/vite/astro.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ test(
9292
// https://astro.build/config
9393
export default defineConfig({ vite: { plugins: [tailwindcss()] }, integrations: [react()] })
9494
`,
95-
// prettier-ignore
9695
'src/pages/index.astro': html`
9796
---
98-
import ClientOnly from '../components/client-only';
97+
import ClientOnly from './client-only';
9998
---
10099
101100
<div class="underline">Hello, world!</div>
@@ -106,7 +105,7 @@ test(
106105
@import 'tailwindcss';
107106
</style>
108107
`,
109-
'src/components/client-only.jsx': js`
108+
'src/pages/client-only.jsx': js`
110109
export default function ClientOnly() {
111110
return <div className="overline">Hello, world!</div>
112111
}

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const INLINE_STYLE_ID_RE = /[?&]index\=\d+\.css$/
1313

1414
const IGNORED_DEPENDENCIES = ['tailwind-merge']
1515

16-
type ScannerMode = 'module-graph' | 'file-system'
16+
type ScannerMode = 'automatic' | 'module-graph' | 'file-system'
1717

1818
export default function tailwindcss(
19-
{ scanner: scannerMode = 'module-graph' }: { scanner: ScannerMode } = {
20-
scanner: 'module-graph',
19+
{ scanner: scannerMode = 'automatic' }: { scanner: ScannerMode } = {
20+
scanner: 'automatic',
2121
},
2222
): Plugin[] {
2323
let servers: ViteDevServer[] = []
@@ -26,8 +26,6 @@ export default function tailwindcss(
2626
let isSSR = false
2727
let minify = false
2828

29-
let additionalFileSystemSources: string[] = []
30-
3129
// The Vite extension has two types of sources for candidates:
3230
//
3331
// 1. The module graph: These are all modules that vite transforms and we want
@@ -69,7 +67,6 @@ export default function tailwindcss(
6967
() => moduleGraphCandidates,
7068
scannerMode,
7169
config!.root,
72-
additionalFileSystemSources,
7370
customCssResolver,
7471
customJsResolver,
7572
)
@@ -212,8 +209,13 @@ export default function tailwindcss(
212209
minify = config.build.cssMinify !== false
213210
isSSR = config.build.ssr !== false && config.build.ssr !== undefined
214211

215-
if (isAstro(config)) {
216-
additionalFileSystemSources.push(path.join(config.root, 'src', 'components'))
212+
if (scannerMode === 'automatic') {
213+
if (shouldDisableModuleGraph(config)) {
214+
console.warn('Detected an Astro.js build and opted-out of using the Vite module graph.')
215+
scannerMode = 'file-system'
216+
return
217+
}
218+
scannerMode = 'module-graph'
217219
}
218220
},
219221

@@ -436,7 +438,6 @@ class Root {
436438
private getSharedCandidates: () => Map<string, Set<string>>,
437439
private scannerMode: ScannerMode,
438440
private base: string,
439-
private additionalFileSystemSources: string[],
440441

441442
private customCssResolver: (id: string, base: string) => Promise<string | false | undefined>,
442443
private customJsResolver: (id: string, base: string) => Promise<string | false | undefined>,
@@ -491,15 +492,6 @@ class Root {
491492
return [this.compiler.root]
492493
})().concat(this.compiler.globs)
493494

494-
if (this.additionalFileSystemSources) {
495-
sources = sources.concat(
496-
this.additionalFileSystemSources.map((source) => ({
497-
base: source,
498-
pattern: '**/*',
499-
})),
500-
)
501-
}
502-
503495
this.scanner = new Scanner({ sources })
504496
}
505497

@@ -616,6 +608,6 @@ class Root {
616608
}
617609
}
618610

619-
function isAstro(config: ResolvedConfig) {
611+
function shouldDisableModuleGraph(config: ResolvedConfig) {
620612
return config.plugins.some((p) => p.name === 'astro:scripts:page-ssr')
621613
}

0 commit comments

Comments
 (0)