1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
1
+ /* eslint-disable
2
+ no-param-reassign
4
3
*/
5
-
6
4
import crypto from 'crypto' ;
7
5
import { SourceMapConsumer } from 'source-map' ;
8
6
import { SourceMapSource , RawSource , ConcatSource } from 'webpack-sources' ;
@@ -14,10 +12,6 @@ import schema from './options.json';
14
12
import Uglify from './uglify' ;
15
13
import versions from './uglify/versions' ;
16
14
17
- /* eslint-disable
18
- no-param-reassign
19
- */
20
-
21
15
const warningRegex = / \[ .+ : ( [ 0 - 9 ] + ) , ( [ 0 - 9 ] + ) \] / ;
22
16
23
17
class UglifyJsPlugin {
@@ -95,7 +89,7 @@ class UglifyJsPlugin {
95
89
apply ( compiler ) {
96
90
const requestShortener = new RequestShortener ( compiler . context ) ;
97
91
98
- const buildMobuleFn = ( moduleArg ) => {
92
+ const buildModuleFn = ( moduleArg ) => {
99
93
// to get detailed location info about errors
100
94
moduleArg . useSourceMap = true ;
101
95
} ;
@@ -105,8 +99,10 @@ class UglifyJsPlugin {
105
99
cache : this . options . cache ,
106
100
parallel : this . options . parallel ,
107
101
} ) ;
102
+
108
103
const uglifiedAssets = new WeakSet ( ) ;
109
104
const tasks = [ ] ;
105
+
110
106
chunks . reduce ( ( acc , chunk ) => acc . concat ( chunk . files || [ ] ) , [ ] )
111
107
. concat ( compilation . additionalChunkAssets || [ ] )
112
108
. filter ( ModuleFilenameHelpers . matchObject . bind ( null , this . options ) )
@@ -164,7 +160,14 @@ class UglifyJsPlugin {
164
160
165
161
tasks . push ( task ) ;
166
162
} catch ( error ) {
167
- compilation . errors . push ( UglifyJsPlugin . buildError ( error , file , sourceMap , requestShortener ) ) ;
163
+ compilation . errors . push (
164
+ UglifyJsPlugin . buildError (
165
+ error ,
166
+ file ,
167
+ sourceMap ,
168
+ requestShortener ,
169
+ ) ,
170
+ ) ;
168
171
}
169
172
} ) ;
170
173
@@ -181,13 +184,25 @@ class UglifyJsPlugin {
181
184
// Handling results
182
185
// Error case: add errors, and go to next file
183
186
if ( error ) {
184
- compilation . errors . push ( UglifyJsPlugin . buildError ( error , file , sourceMap , requestShortener ) ) ;
187
+ compilation . errors . push (
188
+ UglifyJsPlugin . buildError (
189
+ error ,
190
+ file ,
191
+ sourceMap ,
192
+ requestShortener ,
193
+ ) ,
194
+ ) ;
195
+
185
196
return ;
186
197
}
187
198
188
199
let outputSource ;
189
200
if ( map ) {
190
- outputSource = new SourceMapSource ( code , file , JSON . parse ( map ) , input , inputSourceMap ) ;
201
+ outputSource = new SourceMapSource (
202
+ code ,
203
+ file ,
204
+ JSON . parse ( map ) , input , inputSourceMap ,
205
+ ) ;
191
206
} else {
192
207
outputSource = new RawSource ( code ) ;
193
208
}
@@ -197,9 +212,11 @@ class UglifyJsPlugin {
197
212
// Add a banner to the original file
198
213
if ( this . options . extractComments . banner !== false ) {
199
214
let banner = this . options . extractComments . banner || `For license information please see ${ commentsFile } ` ;
215
+
200
216
if ( typeof banner === 'function' ) {
201
217
banner = banner ( commentsFile ) ;
202
218
}
219
+
203
220
if ( banner ) {
204
221
outputSource = new ConcatSource (
205
222
`/*! ${ banner } */\n` , outputSource ,
@@ -208,6 +225,7 @@ class UglifyJsPlugin {
208
225
}
209
226
210
227
const commentsSource = new RawSource ( `${ extractedComments . join ( '\n\n' ) } \n` ) ;
228
+
211
229
if ( commentsFile in compilation . assets ) {
212
230
// commentsFile already exists, append new comments...
213
231
if ( compilation . assets [ commentsFile ] instanceof ConcatSource ) {
@@ -228,14 +246,24 @@ class UglifyJsPlugin {
228
246
229
247
// Handling warnings
230
248
if ( warnings ) {
231
- const warnArr = UglifyJsPlugin . buildWarnings ( warnings , file , sourceMap , this . options . warningsFilter , requestShortener ) ;
249
+ const warnArr = UglifyJsPlugin . buildWarnings (
250
+ warnings ,
251
+ file ,
252
+ sourceMap ,
253
+ this . options . warningsFilter ,
254
+ requestShortener ,
255
+ ) ;
256
+
232
257
if ( warnArr . length > 0 ) {
233
- compilation . warnings . push ( new Error ( `${ file } from UglifyJs\n${ warnArr . join ( '\n' ) } ` ) ) ;
258
+ compilation . warnings . push (
259
+ new Error ( `${ file } from UglifyJs\n${ warnArr . join ( '\n' ) } ` ) ,
260
+ ) ;
234
261
}
235
262
}
236
263
} ) ;
237
264
238
265
uglify . exit ( ) ;
266
+
239
267
callback ( ) ;
240
268
} ) ;
241
269
} ;
@@ -245,15 +273,15 @@ class UglifyJsPlugin {
245
273
246
274
compiler . hooks . compilation . tap ( plugin , ( compilation ) => {
247
275
if ( this . options . sourceMap ) {
248
- compilation . hooks . buildMobule . tap ( plugin , buildMobuleFn ) ;
276
+ compilation . hooks . buildModule . tap ( plugin , buildModuleFn ) ;
249
277
}
250
278
251
279
compilation . hooks . optimizeChunkAssets . tapAsync ( plugin , optimizeFn . bind ( this , compilation ) ) ;
252
280
} ) ;
253
281
} else {
254
282
compiler . plugin ( 'compilation' , ( compilation ) => {
255
283
if ( this . options . sourceMap ) {
256
- compilation . plugin ( 'build-module' , buildMobuleFn ) ;
284
+ compilation . plugin ( 'build-module' , buildModuleFn ) ;
257
285
}
258
286
259
287
compilation . plugin ( 'optimize-chunk-assets' , optimizeFn . bind ( this , compilation ) ) ;
0 commit comments