@@ -24,47 +24,54 @@ module.exports = function f (b, opts) {
24
24
25
25
var needRecords = ! files . length ;
26
26
27
+ opts . outputs = opts . outputs || opts . o ;
27
28
opts . objectMode = true ;
28
29
opts . raw = true ;
29
30
opts . rmap = { } ;
30
31
31
- b . pipeline . get ( 'record' ) . push ( through . obj ( function ( row , enc , next ) {
32
- if ( needRecords ) {
33
- files . push ( row . file ) ;
34
- }
35
- next ( null , row ) ;
36
- } , function ( next ) {
37
- var cwd = defined ( opts . basedir , b . _options . basedir , process . cwd ( ) ) ;
38
- var fileMap = files . reduce ( function ( acc , x , ix ) {
39
- acc [ path . resolve ( cwd , x ) ] = opts . o [ ix ] ;
40
- return acc ;
41
- } , { } ) ;
42
-
43
- // Force browser-pack to wrap the common bundle
44
- b . _bpack . hasExports = true ;
45
- var packOpts = xtend ( b . _options , {
46
- raw : true ,
47
- hasExports : true
48
- } ) ;
49
-
50
- var s = createStream ( files , opts ) ;
51
- s . on ( 'stream' , function ( bundle ) {
52
- var output = fileMap [ bundle . file ] ;
53
- var ws = isStream ( output ) ? output : fs . createWriteStream ( output ) ;
54
-
55
- bundle . pipe ( pack ( packOpts ) ) . pipe ( ws ) ;
56
- } ) ;
57
-
58
- b . pipeline . get ( 'pack' ) . unshift ( s ) ;
59
-
60
- next ( ) ;
61
- } ) ) ;
62
-
63
-
64
- b . pipeline . get ( 'label' ) . push ( through . obj ( function ( row , enc , next ) {
65
- opts . rmap [ row . id ] = row . file ;
66
- next ( null , row ) ;
67
- } ) ) ;
32
+ b . on ( 'reset' , addHooks ) ;
33
+ addHooks ( ) ;
34
+
35
+ function addHooks ( ) {
36
+ b . pipeline . get ( 'record' ) . push ( through . obj ( function ( row , enc , next ) {
37
+ if ( needRecords ) {
38
+ files . push ( row . file ) ;
39
+ }
40
+ next ( null , row ) ;
41
+ } , function ( next ) {
42
+ var cwd = defined ( opts . basedir , b . _options . basedir , process . cwd ( ) ) ;
43
+ var fileMap = files . reduce ( function ( acc , x , ix ) {
44
+ acc [ path . resolve ( cwd , x ) ] = opts . outputs [ ix ] ;
45
+ return acc ;
46
+ } , { } ) ;
47
+
48
+ // Force browser-pack to wrap the common bundle
49
+ b . _bpack . hasExports = true ;
50
+ var packOpts = xtend ( b . _options , {
51
+ raw : true ,
52
+ hasExports : true
53
+ } ) ;
54
+
55
+ var s = createStream ( files , opts ) ;
56
+ s . on ( 'stream' , function ( bundle ) {
57
+ var output = fileMap [ bundle . file ] ;
58
+ var ws = isStream ( output ) ? output : fs . createWriteStream ( output ) ;
59
+
60
+ bundle . pipe ( pack ( packOpts ) ) . pipe ( ws ) ;
61
+ } ) ;
62
+
63
+ b . pipeline . get ( 'pack' ) . unshift ( s ) ;
64
+
65
+ if ( needRecords ) files = [ ] ;
66
+
67
+ next ( ) ;
68
+ } ) ) ;
69
+
70
+ b . pipeline . get ( 'label' ) . push ( through . obj ( function ( row , enc , next ) {
71
+ opts . rmap [ row . id ] = row . file ;
72
+ next ( null , row ) ;
73
+ } ) ) ;
74
+ }
68
75
69
76
return b ;
70
77
0 commit comments