@@ -89,6 +89,10 @@ module.exports = function(context, moduleName, options, callback) {
8989
9090 options . context = options . context || context ;
9191
92+ options . emitFile = options . emitFile || function ( filename , content ) {
93+ options . internal . fileWrites . push ( [ path . join ( options . outputDirectory , filename ) , content ] ) ;
94+ }
95+
9296 if ( options . output ) {
9397 if ( ! options . outputDirectory ) {
9498 options . outputDirectory = path . dirname ( options . output ) ;
@@ -127,8 +131,9 @@ module.exports = function(context, moduleName, options, callback) {
127131 options . postLoaders = options . postLoaders || [ ] ;
128132
129133 options . loader = options . loader || { } ;
130- options . loader . emitFile = options . loader . emitFile || function ( filename , content ) {
131- options . internal . fileWrites . push ( [ path . join ( options . outputDirectory , filename ) , content ] ) ;
134+ options . loader . emitFile = options . loader . emitFile || options . emitFile ;
135+ options . loader . emitSubStats = options . loader . emitSubStats || function ( stats ) {
136+ options . internal . subStats . push ( stats ) ;
132137 }
133138
134139 // Create a options.events as EventEmitter
@@ -216,8 +221,9 @@ function webpack(context, moduleName, options, callback) {
216221
217222 // all writes to files
218223 // items: [filename, content]
219- var fileWrites = [ ] ;
224+ var fileWrites = [ ] , subStats = [ ] ;
220225 options . internal . fileWrites = fileWrites ;
226+ options . internal . subStats = subStats ;
221227
222228 // Some status info
223229 options . events . emit ( "task" , "create ouput directory" ) ;
@@ -277,8 +283,7 @@ function webpack(context, moduleName, options, callback) {
277283 chunksCount ++ ;
278284
279285 // build filename
280- var filename = chunk . filename = path . join ( options . outputDirectory ,
281- chunk . realId === 0 ? options . output : chunk . realId + options . outputPostfix ) ;
286+ var filename = chunk . filename = chunk . realId === 0 ? options . output : chunk . realId + options . outputPostfix ;
282287
283288 // get content of chunk
284289 var content = writeChunk ( depTree , chunk , options ) ;
@@ -301,17 +306,13 @@ function webpack(context, moduleName, options, callback) {
301306 buffer . push ( template ) ;
302307
303308 // write extra info into object
304- if ( chunkIds . length > 1 ) {
305- buffer . push ( "/******/({a:" ) ;
306- buffer . push ( JSON . stringify ( options . outputPostfix . replace ( HASH_REGEXP , hash ) ) ) ;
307- buffer . push ( ",b:" ) ;
308- buffer . push ( JSON . stringify ( options . outputJsonpFunction ) ) ;
309- buffer . push ( ",c:" ) ;
310- buffer . push ( JSON . stringify ( options . publicPrefix . replace ( HASH_REGEXP , hash ) ) ) ;
311- buffer . push ( ",\n" ) ;
312- } else {
313- buffer . push ( "/******/({\n" ) ;
314- }
309+ buffer . push ( "/******/({a:" ) ;
310+ buffer . push ( JSON . stringify ( options . outputPostfix . replace ( HASH_REGEXP , hash ) ) ) ;
311+ buffer . push ( ",b:" ) ;
312+ buffer . push ( JSON . stringify ( options . outputJsonpFunction ) ) ;
313+ buffer . push ( ",c:" ) ;
314+ buffer . push ( JSON . stringify ( options . publicPrefix . replace ( HASH_REGEXP , hash ) ) ) ;
315+ buffer . push ( ",\n" ) ;
315316 } else { // lazy loaded chunk
316317 // write only jsonp function and chunk id as function call
317318 buffer . push ( "/******/" ) ;
@@ -331,14 +332,14 @@ function webpack(context, moduleName, options, callback) {
331332
332333 // minimize if wished
333334 try {
334- if ( options . minimize ) buffer = uglify ( buffer , filename ) ;
335+ if ( options . minimize ) buffer = uglify ( buffer , path . join ( options . outputDirectory , filename ) ) ;
335336 } catch ( e ) {
336337 callback ( e ) ;
337338 return ;
338339 }
339340
340341 // push it as "file write"
341- fileWrites . unshift ( [ filename , buffer ] ) ;
342+ options . emitFile ( filename , buffer ) ;
342343 } ) ;
343344 options . events . emit ( "task-end" , "prepare chunks" ) ;
344345 options . events . emit ( "start-writing" , hash ) ;
@@ -395,6 +396,7 @@ function webpack(context, moduleName, options, callback) {
395396 writingFinished ( ) ;
396397 } ) ;
397398 } ) ;
399+ if ( fileWrites . length == 0 ) writingFinished ( ) ;
398400 }
399401
400402 // after writing: generate statistics
@@ -440,6 +442,7 @@ function webpack(context, moduleName, options, callback) {
440442 buffer . warnings = depTree . warnings ;
441443 buffer . errors = depTree . errors ;
442444 buffer . fileModules = fileModulesMap ;
445+ buffer . subStats = subStats ;
443446 buffer . time = new Date ( ) - startTime ;
444447 options . events . emit ( "task-end" , "statistics" ) ;
445448 options . events . emit ( "bundle" , buffer ) ;
0 commit comments