@@ -61,7 +61,7 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
61
61
if ( requireItem . id !== undefined && toRealId ( requireItem . id ) !== undefined ) {
62
62
var prefix = "" ;
63
63
if ( requireItem . name && options . includeFilenames )
64
- prefix += "/* " + shortenFilename ( requireItem . name ) + " */" ;
64
+ prefix += "/*! " + shortenFilename ( requireItem . name ) + " */" ;
65
65
if ( requireItem . expressionRange ) {
66
66
replaces . push ( {
67
67
from : requireItem . expressionRange [ 0 ] ,
@@ -106,15 +106,15 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
106
106
replaces . push ( {
107
107
from : requireItem . amdNameRange [ 0 ] ,
108
108
to : requireItem . amdNameRange [ 1 ] ,
109
- value : "/* " + requireItem . label . replace ( / \* \/ / g, "* nice try /" ) + " */0"
109
+ value : options . includeFilenames ? "/*! " + requireItem . label . replace ( / \* \/ / g, "* nice try /" ) + " */0" : " 0"
110
110
} ) ;
111
111
}
112
112
}
113
113
function genContextReplaces ( contextItem ) {
114
114
var postfix = "" ;
115
115
var prefix = "" ;
116
- if ( contextItem . name )
117
- prefix += "/* " + contextItem . name + " */" ;
116
+ if ( contextItem . name && options . includeFilenames )
117
+ prefix += "/*! " + contextItem . name + " */" ;
118
118
if ( contextItem . require ) {
119
119
replaces . push ( {
120
120
from : contextItem . calleeRange [ 0 ] ,
@@ -201,7 +201,7 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
201
201
replaces . push ( {
202
202
from : asyncItem . nameRange [ 0 ] ,
203
203
to : asyncItem . nameRange [ 1 ] ,
204
- value : "/* " + asyncItem . name . replace ( / \* \/ / g, "* nice try /" ) + " */0"
204
+ value : options . includeFilenames ? "/*! " + asyncItem . name . replace ( / \* \/ / g, "* nice try /" ) + " */0" : " 0"
205
205
} ) ;
206
206
}
207
207
if ( asyncItem . propertyRange ) {
@@ -248,8 +248,8 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
248
248
values . forEach ( function ( requireItem , idx ) {
249
249
if ( requireItem . id !== undefined && toRealId ( requireItem . id ) !== undefined ) {
250
250
var prefix = "" ;
251
- if ( requireItem . name )
252
- prefix += "/* " + requireItem . name + " */" ;
251
+ if ( requireItem . name && options . includeFilenames )
252
+ prefix += "/*! " + requireItem . name + " */" ;
253
253
values [ idx ] = "require(" + prefix + toRealId ( requireItem . id ) + ")" + ( requireItem . append || "" ) ;
254
254
}
255
255
} ) ;
@@ -290,7 +290,7 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
290
290
// minimize if in debug mode
291
291
// else calculate the minimized size for stats
292
292
if ( options . minimize ) {
293
- var minimized = uglify ( result , module . filename ) ;
293
+ var minimized = uglify ( result , module . request , options . minimize , options . debug ) ;
294
294
module . size = minimized . length ;
295
295
if ( options . debug ) {
296
296
result = minimized ;
@@ -309,7 +309,7 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
309
309
"// module.id = " , module . id , "\n" ,
310
310
"// module.realId = " , module . realId , "\n" ,
311
311
"// module.chunks = " , module . chunks . join ( ", " ) , "\n" ,
312
- "//@ sourceURL=webpack-module:///" , encodeURI ( shortenFilename ( module . request || module . dirname ) ) . replace ( / % 5 C | % 2 F / g, "/" ) . replace ( / ^ \/ / , "" )
312
+ "//@ sourceURL=webpack-module:///" , encodeURI ( shortenFilename ( module . request || module . dirname ) ) . replace ( / % 5 C | % 2 F / g, "/" ) . replace ( / \? / , "%3F" ) . replace ( / ^ \/ / , "" )
313
313
] . join ( "" ) ) ,
314
314
");" ] . join ( "" ) ;
315
315
}
@@ -320,15 +320,30 @@ module.exports = function(module, options, toRealId, toRealChuckId) {
320
320
return finalResult . join ( "" ) ;
321
321
}
322
322
323
- function uglify ( input , filename ) {
324
- var uglify = require ( "uglify-js" ) ;
323
+ // minimize it the uglify
324
+ function uglify ( input , filename , options , beautify ) {
325
+ if ( typeof options != "object" ) options = {
326
+ warnings : false
327
+ } ;
328
+ var uglify2 = require ( "uglify-js2" ) ;
325
329
try {
326
- source = uglify . parser . parse ( input ) ;
327
- source = uglify . uglify . ast_mangle ( source ) ;
328
- source = uglify . uglify . ast_squeeze ( source ) ;
329
- source = uglify . uglify . gen_code ( source ) ;
330
+ var ast = uglify2 . parse ( input , {
331
+ filename : filename
332
+ } ) ;
333
+ ast . figure_out_scope ( )
334
+ if ( options . compress !== false ) {
335
+ var compressor = uglify2 . Compressor ( options ) ;
336
+ ast = ast . transform ( compressor ) ;
337
+ ast . figure_out_scope ( ) ;
338
+ ast . compute_char_frequency ( options . mangle || { } ) ;
339
+ ast . mangle_names ( options . mangle || { } ) ;
340
+ }
341
+ var source = ast . print_to_string ( {
342
+ comments : options . comments || / ^ \* * ! | @ p r e s e r v e | @ l i c e n s e / ,
343
+ beautify : beautify
344
+ } ) ;
330
345
} catch ( e ) {
331
- throw new Error ( filename + " @ Line " + e . line + ", Col " + e . col + ", " + e . message ) ;
346
+ throw new Error ( filename + " @ Line " + e . line + ", Col " + e . col + ", " + e ) ;
332
347
return input ;
333
348
}
334
349
return source ;
0 commit comments