@@ -79,11 +79,6 @@ export default function tailwindcss(): Plugin[] {
7979 for ( let [ id , root ] of roots . entries ( ) ) {
8080 let module = server . moduleGraph . getModuleById ( id )
8181 if ( ! module ) {
82- // The module for this root might not exist yet
83- if ( root . builtBeforeTransform ) {
84- continue
85- }
86-
8782 // Note: Removing this during SSR is not safe and will produce
8883 // inconsistent results based on the timing of the removal and
8984 // the order / timing of transforms.
@@ -184,7 +179,6 @@ export default function tailwindcss(): Plugin[] {
184179 }
185180
186181 return [
187- svelteProcessor ( roots ) ,
188182 {
189183 // Step 1: Scan source files for candidates
190184 name : '@tailwindcss/vite:scan' ,
@@ -225,19 +219,6 @@ export default function tailwindcss(): Plugin[] {
225219
226220 let root = roots . get ( id )
227221
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-
241222 if ( ! options ?. ssr ) {
242223 // Wait until all other files have been processed, so we can extract
243224 // all candidates before generating CSS. This must not be called
@@ -272,19 +253,6 @@ export default function tailwindcss(): Plugin[] {
272253
273254 let root = roots . get ( id )
274255
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-
288256 // We do a first pass to generate valid CSS for the downstream plugins.
289257 // However, since not all candidates are guaranteed to be extracted by
290258 // this time, we have to re-run a transform for the root later.
@@ -304,9 +272,6 @@ export default function tailwindcss(): Plugin[] {
304272 I . start ( '[@tailwindcss/vite] (render start)' )
305273
306274 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-
310275 let generated = await regenerateOptimizedCss (
311276 root ,
312277 // During the renderStart phase, we can not add watch files since
@@ -341,23 +306,13 @@ function isPotentialCssRootFile(id: string) {
341306 if ( id . includes ( '/.vite/' ) ) return
342307 let extension = getExtension ( id )
343308 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' ) ) &&
350310 // Don't intercept special static asset resources
351311 ! SPECIAL_QUERY_RE . test ( id )
352312
353313 return isCssFile
354314}
355315
356- function isSvelteStyle ( id : string ) {
357- let extension = getExtension ( id )
358- return extension === 'svelte' && id . includes ( '&lang.css' )
359- }
360-
361316function optimizeCss (
362317 input : string ,
363318 { file = 'input.css' , minify = false } : { file ?: string ; minify ?: boolean } = { } ,
@@ -425,14 +380,6 @@ class Root {
425380 // `renderStart` hook.
426381 public lastContent : string = ''
427382
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-
436383 // The lazily-initialized Tailwind compiler components. These are persisted
437384 // throughout rebuilds but will be re-initialized if the rebuild strategy is
438385 // set to `full`.
@@ -626,75 +573,3 @@ class Root {
626573 return shared
627574 }
628575}
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