@@ -9,7 +9,7 @@ var FileSystemLoader = require('./file-system-loader');
9
9
var assign = require ( 'object-assign' ) ;
10
10
var stringHash = require ( 'string-hash' ) ;
11
11
var ReadableStream = require ( 'stream' ) . Readable ;
12
- var through = require ( 'through ' ) ;
12
+ var through = require ( 'through2 ' ) ;
13
13
14
14
/*
15
15
Custom `generateScopedName` function for `postcss-modules-scope`.
@@ -201,14 +201,17 @@ module.exports = function (browserify, options) {
201
201
202
202
// ----
203
203
204
- browserify . on ( 'bundle' , function ( bundle ) {
205
- // on each bundle, create a new stream b/c the old one might have ended
206
- var compiledCssStream = new ReadableStream ( ) ;
207
- compiledCssStream . _read = function ( ) { } ;
204
+ function addHooks ( ) {
205
+ browserify . pipeline . get ( 'pack' ) . push ( through ( function write ( row , enc , next ) {
206
+ next ( null , row )
207
+ } , function end ( cb ) {
208
208
209
- browserify . emit ( 'css stream' , compiledCssStream ) ;
209
+ // on each bundle, create a new stream b/c the old one might have ended
210
+ var compiledCssStream = new ReadableStream ( ) ;
211
+ compiledCssStream . _read = function ( ) { } ;
212
+
213
+ browserify . emit ( 'css stream' , compiledCssStream ) ;
210
214
211
- browserify . pipeline . get ( 'pack' ) . push ( through ( null , function ( ) {
212
215
// Combine the collected sources for a single bundle into a single CSS file
213
216
var self = this ;
214
217
var loader = loadersByFile [ cssOutFilename ] ;
@@ -229,13 +232,14 @@ module.exports = function (browserify, options) {
229
232
if ( jsonOutFilename ) {
230
233
writes . push ( writeFile ( jsonOutFilename , JSON . stringify ( normalizeManifestPaths ( tokensByFile , rootDir ) ) ) ) ;
231
234
}
232
-
233
235
Promise . all ( writes )
234
- . then ( function ( ) { self . queue ( null ) ; } )
235
- . catch ( function ( err ) { self . emit ( 'error' , err ) ; } )
236
+ . then ( function ( ) { cb ( ) ; } )
237
+ . catch ( function ( err ) { self . emit ( 'error' , err ) ; cb ( ) } )
236
238
} ) ) ;
237
- } ) ;
239
+ }
238
240
241
+ browserify . on ( 'reset' , addHooks ) ;
242
+ addHooks ( ) ;
239
243
240
244
return browserify ;
241
245
} ;
0 commit comments