@@ -138,6 +138,8 @@ function rc(ctx, path) {
138138function files ( files ) {
139139 if ( typeof files === 'string' ) files = [ files ]
140140
141+ const appendCSS = shouldAppendCSS ( )
142+
141143 return Promise . all (
142144 files . map ( file => {
143145 if ( file === 'stdin' ) {
@@ -147,12 +149,12 @@ function files(files) {
147149 } )
148150 }
149151
150- return read ( file ) . then ( content => css ( content , file ) )
152+ return read ( file ) . then ( content => css ( content , file , appendCSS ) )
151153 } )
152154 )
153155}
154156
155- function css ( css , file ) {
157+ function css ( css , file , appendCSS ) {
156158 const ctx = { options : config . options }
157159
158160 if ( file !== 'stdin' ) {
@@ -210,7 +212,11 @@ function css(css, file) {
210212 const tasks = [ ]
211213
212214 if ( options . to ) {
213- tasks . push ( fs . outputFile ( options . to , result . css ) )
215+ if ( appendCSS ) {
216+ tasks . push ( fs . appendFile ( options . to , result . css ) )
217+ } else {
218+ tasks . push ( fs . outputFile ( options . to , result . css ) )
219+ }
214220
215221 if ( result . map ) {
216222 tasks . push (
@@ -293,3 +299,11 @@ function error(err) {
293299 }
294300 process . exit ( 1 )
295301}
302+
303+ function shouldAppendCSS ( ) {
304+ const hasOutputFile = ! ! argv . output
305+ const hasMultipleFiles = ( input . length > 1 )
306+
307+ return hasMultipleFiles && hasOutputFile
308+ }
309+
0 commit comments