11import postcss from 'postcss'
2- import replaceSymbols , { replaceAll } from 'icss-replace-symbols'
2+ import replaceSymbols , { replaceAll } from 'icss-replace-symbols'
33
44const matchImports = / ^ ( .+ ?) \s + f r o m \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | [ \w - ] + ) $ /
55const matchValueDefinition = / (?: , \s + | ^ ) ( [ \w - ] + ) : ? \s + ( " [ ^ " ] * " | ' [ ^ ' ] * ' | \w + \( [ ^ \) ] + \) | [ ^ , ] + ) \s ? / g
@@ -34,12 +34,12 @@ export default (css, result) => {
3434 let [ /*match*/ , theirName , myName = theirName ] = tokens
3535 let importedName = createImportedName ( myName )
3636 definitions [ myName ] = importedName
37- return { theirName, importedName}
37+ return { theirName, importedName }
3838 } else {
3939 throw new Error ( `@import statement "${ alias } " is invalid!` )
4040 }
4141 } )
42- importAliases . push ( { path, imports} )
42+ importAliases . push ( { path, imports } )
4343 atRule . remove ( )
4444 }
4545 }
@@ -58,12 +58,11 @@ export default (css, result) => {
5858 } )
5959
6060 /* We want to export anything defined by now, but don't add it to the CSS yet or
61- it well get picked up by the replacement stuff */
61+ it well get picked up by the replacement stuff */
6262 let exportDeclarations = Object . keys ( definitions ) . map ( key => postcss . decl ( {
6363 value : definitions [ key ] ,
6464 prop : key ,
65- raws : { before : "\n " } ,
66- _autoprefixerDisabled : true
65+ raws : { before : "\n " }
6766 } ) )
6867
6968 /* If we have no definitions, don't continue */
@@ -74,24 +73,28 @@ export default (css, result) => {
7473
7574 /* Add export rules if any */
7675 if ( exportDeclarations . length > 0 ) {
77- css . prepend ( postcss . rule ( {
76+ let exportRule = postcss . rule ( {
7877 selector : `:export` ,
79- raws : { after : "\n" } ,
80- nodes : exportDeclarations
81- } ) )
78+ raws : { after : "\n" }
79+ } )
80+ exportRule . append ( exportDeclarations )
81+ css . prepend ( exportRule )
8282 }
8383
8484 /* Add import rules */
85- importAliases . reverse ( ) . forEach ( ( { path, imports} ) => {
86- css . prepend ( postcss . rule ( {
85+ importAliases . reverse ( ) . forEach ( ( { path, imports } ) => {
86+ let importRule = postcss . rule ( {
8787 selector : `:import(${ path } )` ,
88- raws : { after : "\n" } ,
89- nodes : imports . map ( ( { theirName, importedName} ) => postcss . decl ( {
88+ raws : { after : "\n" }
89+ } )
90+ imports . forEach ( ( { theirName, importedName } ) => {
91+ importRule . append ( {
9092 value : theirName ,
9193 prop : importedName ,
92- raws : { before : "\n " } ,
93- _autoprefixerDisabled : true
94- } ) )
95- } ) )
94+ raws : { before : "\n " }
95+ } )
96+ } )
97+
98+ css . prepend ( importRule )
9699 } )
97100}
0 commit comments