@@ -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
@@ -344,20 +309,13 @@ function isPotentialCssRootFile(id: string) {
344
309
( extension === 'css' ||
345
310
( extension === 'vue' && id . includes ( '&lang.css' ) ) ||
346
311
( 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 ) ) &&
312
+ ( extension === 'svelte' && id . includes ( '&lang.css' ) ) )
350
313
// Don't intercept special static asset resources
351
314
! SPECIAL_QUERY_RE . test ( id )
352
315
353
316
return isCssFile
354
317
}
355
318
356
- function isSvelteStyle ( id : string ) {
357
- let extension = getExtension ( id )
358
- return extension === 'svelte' && id . includes ( '&lang.css' )
359
- }
360
-
361
319
function optimizeCss (
362
320
input : string ,
363
321
{ file = 'input.css' , minify = false } : { file ?: string ; minify ?: boolean } = { } ,
@@ -422,14 +380,6 @@ class Root {
422
380
// `renderStart` hook.
423
381
public lastContent : string = ''
424
382
425
- // When set, indicates that the root was built before the Vite transform hook
426
- // was being called. This can happen in scenarios like when preprocessing
427
- // `<style>` tags for Svelte components.
428
- //
429
- // It can be set to a list of dependencies that will be added whenever the
430
- // next `transform` hook is being called.
431
- public builtBeforeTransform : string [ ] | undefined
432
-
433
383
// The lazily-initialized Tailwind compiler components. These are persisted
434
384
// throughout rebuilds but will be re-initialized if the rebuild strategy is
435
385
// set to `full`.
@@ -623,75 +573,3 @@ class Root {
623
573
return shared
624
574
}
625
575
}
626
-
627
- // Register a plugin that can hook into the Svelte preprocessor if Svelte is
628
- // configured. This allows us to transform CSS in `<style>` tags and create a
629
- // stricter version of CSS that passes the Svelte compiler.
630
- //
631
- // Note that these files will not undergo a second pass through the vite
632
- // transpiler later. This means that `@tailwind utilities;` will not be up to
633
- // date.
634
- //
635
- // In practice, it is discouraged to use `@tailwind utilities;` inside Svelte
636
- // components, as the styles it create would be scoped anyways. Use an external
637
- // `.css` file instead.
638
- function svelteProcessor ( roots : DefaultMap < string , Root > ) : Plugin {
639
- return {
640
- name : '@tailwindcss/svelte' ,
641
- api : {
642
- sveltePreprocess : {
643
- async style ( {
644
- content,
645
- filename,
646
- markup,
647
- } : {
648
- content : string
649
- filename ?: string
650
- markup : string
651
- } ) {
652
- if ( ! filename ) return
653
- using I = new Instrumentation ( )
654
- DEBUG && I . start ( '[@tailwindcss/vite] Preprocess svelte' )
655
-
656
- // Create the ID used by Vite to identify the `<style>` contents. This
657
- // way, the Vite `transform` hook can find the right root and thus
658
- // track the right dependencies.
659
- let id = filename + '?svelte&type=style&lang.css'
660
-
661
- let root = roots . get ( id )
662
-
663
- // Since a Svelte pre-processor call means that the CSS has changed,
664
- // we need to trigger a rebuild.
665
- root . requiresRebuild = true
666
-
667
- // Mark this root as being built before the Vite transform hook is
668
- // called. We capture all eventually added dependencies so that we can
669
- // connect them to the vite module graph later, when the transform
670
- // hook is called.
671
- root . builtBeforeTransform = [ ]
672
-
673
- // We only want to consider candidates from the current template file,
674
- // this ensures that no one can depend on this having the full candidate
675
- // list in some builds (as this is undefined behavior).
676
- let scanner = new Scanner ( { } )
677
- root . overwriteCandidates = scanner . scanFiles ( [
678
- { content : markup , file : filename , extension : 'svelte' } ,
679
- ] )
680
-
681
- let generated = await root . generate (
682
- content ,
683
- ( file ) => root . builtBeforeTransform ?. push ( file ) ,
684
- I ,
685
- )
686
-
687
- if ( ! generated ) {
688
- roots . delete ( id )
689
- return
690
- }
691
-
692
- return { code : generated }
693
- } ,
694
- } ,
695
- } ,
696
- }
697
- }
0 commit comments