@@ -99,7 +99,7 @@ module.exports = function (browserify, options) {
9999
100100 var cssOutFilename = options . output || options . o ;
101101 var jsonOutFilename = options . json || options . jsonOutput ;
102- var sourceKey = cssOutFilename ;
102+ transformOpts . cssOutFilename = cssOutFilename ;
103103
104104 // PostCSS plugins passed to FileSystemLoader
105105 var plugins = options . use || options . u ;
@@ -142,16 +142,11 @@ module.exports = function (browserify, options) {
142142 return plugin ;
143143 } ) ;
144144
145- // get (or create) a loader for this entry file
146- var loader = loadersByFile [ sourceKey ] ;
147- if ( ! loader ) {
148- loader = loadersByFile [ sourceKey ] = new FileSystemLoader ( rootDir , plugins ) ;
145+ // create a loader for this entry file
146+ if ( ! loadersByFile [ cssOutFilename ] ) {
147+ loadersByFile [ cssOutFilename ] = new FileSystemLoader ( rootDir , plugins ) ;
149148 }
150149
151- // the compiled CSS stream needs to be avalible to the transform,
152- // but re-created on each bundle call.
153- var compiledCssStream ;
154-
155150 // TODO: clean this up so there's less scope crossing
156151 Cmify . prototype . _flush = function ( callback ) {
157152 var self = this ;
@@ -160,6 +155,9 @@ module.exports = function (browserify, options) {
160155 // only handle .css files
161156 if ( ! this . isCssFile ( filename ) ) { return callback ( ) ; }
162157
158+ // grab the correct loader
159+ var loader = loadersByFile [ this . _cssOutFilename ] ;
160+
163161 // convert css to js before pushing
164162 // reset the `tokensByFile` cache
165163 var relFilename = path . relative ( rootDir , filename ) ;
@@ -203,13 +201,14 @@ module.exports = function (browserify, options) {
203201
204202 browserify . on ( 'bundle' , function ( bundle ) {
205203 // on each bundle, create a new stream b/c the old one might have ended
206- compiledCssStream = new ReadableStream ( ) ;
204+ var compiledCssStream = new ReadableStream ( ) ;
207205 compiledCssStream . _read = function ( ) { } ;
208206
209207 bundle . emit ( 'css stream' , compiledCssStream ) ;
210208
211209 bundle . on ( 'end' , function ( ) {
212210 // Combine the collected sources for a single bundle into a single CSS file
211+ var loader = loadersByFile [ cssOutFilename ] ;
213212 var css = loader . finalSource ;
214213
215214 // end the output stream
0 commit comments