@@ -9,8 +9,6 @@ var fs = require("fs");
99
1010var HASH_REGEXP = / \[ h a s h \] / i;
1111
12- var templateAsync = require ( "fs" ) . readFileSync ( path . join ( __dirname , "templateAsync.js" ) ) ;
13- var templateSingle = require ( "fs" ) . readFileSync ( path . join ( __dirname , "templateSingle.js" ) ) ;
1412/*
1513 webpack(context, moduleName, options, callback);
1614 webpack(context, moduleName, callback);
@@ -168,15 +166,15 @@ function webpack(context, moduleName, options, finalCallback) {
168166 chunkIds . sort ( function ( a , b ) {
169167 return parseInt ( b , 10 ) - parseInt ( a , 10 ) ;
170168 } ) ;
169+ var template = getTemplate ( options , { chunks : chunkIds . length > 1 } ) ;
171170 var hash ;
172171 try {
173172 hash = new ( require ( "crypto" ) . Hash ) ( "md5" ) ;
174173 hash . update ( JSON . stringify ( options . libary || "" ) ) ;
175174 hash . update ( JSON . stringify ( options . outputPostfix ) ) ;
176175 hash . update ( JSON . stringify ( options . outputJsonpFunction ) ) ;
177176 hash . update ( JSON . stringify ( options . scriptSrcPrefix ) ) ;
178- hash . update ( templateAsync ) ;
179- hash . update ( templateSingle ) ;
177+ hash . update ( template ) ;
180178 hash . update ( "1" ) ;
181179 } catch ( e ) {
182180 callback ( e ) ;
@@ -204,7 +202,7 @@ function webpack(context, moduleName, options, finalCallback) {
204202 buffer . push ( "=\n" ) ;
205203 }
206204 if ( chunkIds . length > 1 ) {
207- buffer . push ( templateAsync ) ;
205+ buffer . push ( template ) ;
208206 buffer . push ( "/******/({a:" ) ;
209207 buffer . push ( JSON . stringify ( options . outputPostfix . replace ( HASH_REGEXP , hash ) ) ) ;
210208 buffer . push ( ",b:" ) ;
@@ -213,7 +211,7 @@ function webpack(context, moduleName, options, finalCallback) {
213211 buffer . push ( JSON . stringify ( options . scriptSrcPrefix . replace ( HASH_REGEXP , hash ) ) ) ;
214212 buffer . push ( ",\n" ) ;
215213 } else {
216- buffer . push ( templateSingle ) ;
214+ buffer . push ( template ) ;
217215 buffer . push ( "/******/({\n" ) ;
218216 }
219217 } else {
@@ -331,7 +329,7 @@ function webpack(context, moduleName, options, finalCallback) {
331329 buffer . push ( options . libary ) ;
332330 buffer . push ( "=\n" ) ;
333331 }
334- buffer . push ( templateSingle ) ;
332+ buffer . push ( getTemplate ( options , { chunks : false } ) ) ;
335333 buffer . push ( "/******/({\n" ) ;
336334 buffer . push ( writeChunk ( depTree , options ) ) ;
337335 buffer . push ( "/******/})" ) ;
@@ -347,6 +345,16 @@ function webpack(context, moduleName, options, finalCallback) {
347345 return options . events ;
348346}
349347
348+ function getTemplate ( options , templateOptions ) {
349+ if ( options . template ) {
350+ if ( typeof options . template === "string" )
351+ return require ( options . template ) ( options , templateOptions ) ;
352+ else
353+ return options . template ( options , templateOptions ) ;
354+ } else
355+ return require ( "../templates/browser" ) ( options , templateOptions ) ;
356+ }
357+
350358function uglify ( input , filename ) {
351359 var uglify = require ( "uglify-js" ) ;
352360 try {
0 commit comments