1
1
import fs from 'fs'
2
+ import _ from 'lodash'
2
3
import postcss from 'postcss'
3
4
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
+
4
11
export default function ( config , { components : pluginComponents } , generatedUtilities ) {
5
12
return function ( css ) {
6
13
css . walkAtRules ( 'tailwind' , atRule => {
@@ -9,31 +16,17 @@ export default function(config, { components: pluginComponents }, generatedUtili
9
16
fs . readFileSync ( `${ __dirname } /../../css/preflight.css` , 'utf8' )
10
17
)
11
18
12
- preflightTree . walk ( node => ( node . source = atRule . source ) )
13
-
14
- atRule . before ( preflightTree )
19
+ atRule . before ( updateSource ( preflightTree , atRule . source ) )
15
20
atRule . remove ( )
16
21
}
17
22
18
23
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 ) )
26
25
atRule . remove ( )
27
26
}
28
27
29
28
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 ) )
37
30
atRule . remove ( )
38
31
}
39
32
} )
0 commit comments