@@ -11,15 +11,23 @@ import substituteScreenAtRules from './substituteScreenAtRules'
1111import prefixSelector from '../util/prefixSelector'
1212import { useMemo } from '../util/useMemo'
1313
14- function hasAtRule ( css , atRule , condition = ( ) => true ) {
14+ function hasAtRule ( css , atRule , condition ) {
1515 let found = false
1616
17- css . walkAtRules ( atRule , ( node ) => {
18- if ( condition ( node ) ) {
19- found = true
20- return false
21- }
22- } )
17+ css . walkAtRules (
18+ atRule ,
19+ condition === undefined
20+ ? ( ) => {
21+ found = true
22+ return false
23+ }
24+ : ( node ) => {
25+ if ( condition ( node ) ) {
26+ found = true
27+ return false
28+ }
29+ }
30+ )
2331
2432 return found
2533}
@@ -309,8 +317,7 @@ export default function substituteClassApplyAtRules(config, getProcessedPlugins,
309317 return css
310318 }
311319
312- // Tree already contains @tailwind rules, don't prepend default Tailwind tree
313- let requiredTailwindAtRules = [ 'utilities' ]
320+ let requiredTailwindAtRules = [ 'base' , 'utilities' , 'components' ]
314321 if (
315322 hasAtRule ( css , 'tailwind' , ( node ) => {
316323 let idx = requiredTailwindAtRules . indexOf ( node . params )
@@ -319,11 +326,16 @@ export default function substituteClassApplyAtRules(config, getProcessedPlugins,
319326 return false
320327 } )
321328 ) {
329+ // Tree already contains all the at rules (requiredTailwindAtRules)
322330 return processApplyAtRules ( css , postcss . root ( ) , config )
323331 }
324332
325- // Tree contains no @tailwind rules, so generate all of Tailwind's styles and
326- // prepend them to the user's CSS. Important for <style> blocks in Vue components.
333+ // We mutated the `requiredTailwindAtRules`, but when we hit this point in
334+ // time, it means that we don't have all the atrules. The missing atrules
335+ // are listed inside the requiredTailwindAtRules, which we can use to fill
336+ // in the missing pieces.
337+ //
338+ // Important for <style> blocks in Vue components.
327339 const generateLookupTree =
328340 configChanged || defaultTailwindTree === null
329341 ? ( ) => {
@@ -335,14 +347,9 @@ export default function substituteClassApplyAtRules(config, getProcessedPlugins,
335347 convertLayerAtRulesToControlComments ( config ) ,
336348 substituteScreenAtRules ( config ) ,
337349 ] )
338- . process (
339- `
340- @tailwind base;
341- @tailwind components;
342- @tailwind utilities;
343- ` ,
344- { from : undefined }
345- )
350+ . process ( requiredTailwindAtRules . map ( ( rule ) => `@tailwind ${ rule } ;` ) . join ( '\n' ) , {
351+ from : undefined ,
352+ } )
346353 . then ( ( result ) => {
347354 defaultTailwindTree = result
348355 return defaultTailwindTree
0 commit comments