11import fs from 'fs'
2+ import _ from 'lodash'
23import postcss from 'postcss'
34
5+ function updateSource ( nodes , source ) {
6+ return _ . tap ( Array . isArray ( nodes ) ? postcss . root ( { nodes } ) : nodes , tree => {
7+ tree . walk ( node => ( node . source = source ) )
8+ } )
9+ }
10+
411export default function ( config , { components : pluginComponents } , generatedUtilities ) {
512 return function ( css ) {
613 css . walkAtRules ( 'tailwind' , atRule => {
@@ -9,31 +16,17 @@ export default function(config, { components: pluginComponents }, generatedUtili
916 fs . readFileSync ( `${ __dirname } /../../css/preflight.css` , 'utf8' )
1017 )
1118
12- preflightTree . walk ( node => ( node . source = atRule . source ) )
13-
14- atRule . before ( preflightTree )
19+ atRule . before ( updateSource ( preflightTree , atRule . source ) )
1520 atRule . remove ( )
1621 }
1722
1823 if ( atRule . params === 'components' ) {
19- const pluginComponentTree = postcss . root ( {
20- nodes : pluginComponents ,
21- } )
22-
23- pluginComponentTree . walk ( node => ( node . source = atRule . source ) )
24-
25- atRule . before ( pluginComponentTree )
24+ atRule . before ( updateSource ( pluginComponents , atRule . source ) )
2625 atRule . remove ( )
2726 }
2827
2928 if ( atRule . params === 'utilities' ) {
30- const utilityTree = postcss . root ( {
31- nodes : generatedUtilities ,
32- } )
33-
34- utilityTree . walk ( node => ( node . source = atRule . source ) )
35-
36- atRule . before ( utilityTree )
29+ atRule . before ( updateSource ( generatedUtilities , atRule . source ) )
3730 atRule . remove ( )
3831 }
3932 } )
0 commit comments