@@ -79,11 +79,6 @@ export default function tailwindcss(): Plugin[] {
79
79
for ( let [ id , root ] of roots . entries ( ) ) {
80
80
let module = server . moduleGraph . getModuleById ( id )
81
81
if ( ! module ) {
82
- // The module for this root might not exist yet
83
- if ( root . builtBeforeTransform ) {
84
- continue
85
- }
86
-
87
82
// Note: Removing this during SSR is not safe and will produce
88
83
// inconsistent results based on the timing of the removal and
89
84
// the order / timing of transforms.
@@ -184,7 +179,6 @@ export default function tailwindcss(): Plugin[] {
184
179
}
185
180
186
181
return [
187
- svelteProcessor ( roots ) ,
188
182
{
189
183
// Step 1: Scan source files for candidates
190
184
name : '@tailwindcss/vite:scan' ,
@@ -225,19 +219,6 @@ export default function tailwindcss(): Plugin[] {
225
219
226
220
let root = roots . get ( id )
227
221
228
- // If the root was built outside of the transform hook (e.g. in the
229
- // Svelte preprocessor), we still want to mark all dependencies of the
230
- // root as watched files.
231
- if ( root . builtBeforeTransform ) {
232
- root . builtBeforeTransform . forEach ( ( file ) => this . addWatchFile ( file ) )
233
- root . builtBeforeTransform = undefined
234
- }
235
-
236
- // We only process Svelte `<style>` tags in the `sveltePreprocessor`
237
- if ( isSvelteStyle ( id ) ) {
238
- return src
239
- }
240
-
241
222
if ( ! options ?. ssr ) {
242
223
// Wait until all other files have been processed, so we can extract
243
224
// all candidates before generating CSS. This must not be called
@@ -272,19 +253,6 @@ export default function tailwindcss(): Plugin[] {
272
253
273
254
let root = roots . get ( id )
274
255
275
- // If the root was built outside of the transform hook (e.g. in the
276
- // Svelte preprocessor), we still want to mark all dependencies of the
277
- // root as watched files.
278
- if ( root . builtBeforeTransform ) {
279
- root . builtBeforeTransform . forEach ( ( file ) => this . addWatchFile ( file ) )
280
- root . builtBeforeTransform = undefined
281
- }
282
-
283
- // We only process Svelte `<style>` tags in the `sveltePreprocessor`
284
- if ( isSvelteStyle ( id ) ) {
285
- return src
286
- }
287
-
288
256
// We do a first pass to generate valid CSS for the downstream plugins.
289
257
// However, since not all candidates are guaranteed to be extracted by
290
258
// this time, we have to re-run a transform for the root later.
@@ -304,9 +272,6 @@ export default function tailwindcss(): Plugin[] {
304
272
I . start ( '[@tailwindcss/vite] (render start)' )
305
273
306
274
for ( let [ id , root ] of roots . entries ( ) ) {
307
- // Do not do a second render pass on Svelte `<style>` tags.
308
- if ( isSvelteStyle ( id ) ) continue
309
-
310
275
let generated = await regenerateOptimizedCss (
311
276
root ,
312
277
// During the renderStart phase, we can not add watch files since
@@ -341,23 +306,13 @@ function isPotentialCssRootFile(id: string) {
341
306
if ( id . includes ( '/.vite/' ) ) return
342
307
let extension = getExtension ( id )
343
308
let isCssFile =
344
- ( extension === 'css' ||
345
- ( extension === 'vue' && id . includes ( '&lang.css' ) ) ||
346
- ( extension === 'astro' && id . includes ( '&lang.css' ) ) ||
347
- // We want to process Svelte `<style>` tags to properly add dependency
348
- // tracking for imported files.
349
- isSvelteStyle ( id ) ) &&
309
+ ( extension === 'css' || id . includes ( '&lang.css' ) ) &&
350
310
// Don't intercept special static asset resources
351
311
! SPECIAL_QUERY_RE . test ( id )
352
312
353
313
return isCssFile
354
314
}
355
315
356
- function isSvelteStyle ( id : string ) {
357
- let extension = getExtension ( id )
358
- return extension === 'svelte' && id . includes ( '&lang.css' )
359
- }
360
-
361
316
function optimizeCss (
362
317
input : string ,
363
318
{ file = 'input.css' , minify = false } : { file ?: string ; minify ?: boolean } = { } ,
@@ -425,14 +380,6 @@ class Root {
425
380
// `renderStart` hook.
426
381
public lastContent : string = ''
427
382
428
- // When set, indicates that the root was built before the Vite transform hook
429
- // was being called. This can happen in scenarios like when preprocessing
430
- // `<style>` tags for Svelte components.
431
- //
432
- // It can be set to a list of dependencies that will be added whenever the
433
- // next `transform` hook is being called.
434
- public builtBeforeTransform : string [ ] | undefined
435
-
436
383
// The lazily-initialized Tailwind compiler components. These are persisted
437
384
// throughout rebuilds but will be re-initialized if the rebuild strategy is
438
385
// set to `full`.
@@ -626,75 +573,3 @@ class Root {
626
573
return shared
627
574
}
628
575
}
629
-
630
- // Register a plugin that can hook into the Svelte preprocessor if Svelte is
631
- // configured. This allows us to transform CSS in `<style>` tags and create a
632
- // stricter version of CSS that passes the Svelte compiler.
633
- //
634
- // Note that these files will not undergo a second pass through the vite
635
- // transpiler later. This means that `@tailwind utilities;` will not be up to
636
- // date.
637
- //
638
- // In practice, it is discouraged to use `@tailwind utilities;` inside Svelte
639
- // components, as the styles it create would be scoped anyways. Use an external
640
- // `.css` file instead.
641
- function svelteProcessor ( roots : DefaultMap < string , Root > ) : Plugin {
642
- return {
643
- name : '@tailwindcss/svelte' ,
644
- api : {
645
- sveltePreprocess : {
646
- async style ( {
647
- content,
648
- filename,
649
- markup,
650
- } : {
651
- content : string
652
- filename ?: string
653
- markup : string
654
- } ) {
655
- if ( ! filename ) return
656
- using I = new Instrumentation ( )
657
- DEBUG && I . start ( '[@tailwindcss/vite] Preprocess svelte' )
658
-
659
- // Create the ID used by Vite to identify the `<style>` contents. This
660
- // way, the Vite `transform` hook can find the right root and thus
661
- // track the right dependencies.
662
- let id = filename + '?svelte&type=style&lang.css'
663
-
664
- let root = roots . get ( id )
665
-
666
- // Since a Svelte pre-processor call means that the CSS has changed,
667
- // we need to trigger a rebuild.
668
- root . requiresRebuild = true
669
-
670
- // Mark this root as being built before the Vite transform hook is
671
- // called. We capture all eventually added dependencies so that we can
672
- // connect them to the vite module graph later, when the transform
673
- // hook is called.
674
- root . builtBeforeTransform = [ ]
675
-
676
- // We only want to consider candidates from the current template file,
677
- // this ensures that no one can depend on this having the full candidate
678
- // list in some builds (as this is undefined behavior).
679
- let scanner = new Scanner ( { } )
680
- root . overwriteCandidates = scanner . scanFiles ( [
681
- { content : markup , file : filename , extension : 'svelte' } ,
682
- ] )
683
-
684
- let generated = await root . generate (
685
- content ,
686
- ( file ) => root . builtBeforeTransform ?. push ( file ) ,
687
- I ,
688
- )
689
-
690
- if ( ! generated ) {
691
- roots . delete ( id )
692
- return
693
- }
694
-
695
- return { code : generated }
696
- } ,
697
- } ,
698
- } ,
699
- }
700
- }
0 commit comments