@@ -15,12 +15,12 @@ function UglifyJsPlugin(options) {
1515 this . options = options ;
1616}
1717module . exports = UglifyJsPlugin ;
18+
1819UglifyJsPlugin . prototype . apply = function ( compiler ) {
1920 var options = this . options ;
20- var skipFile = options . skipFile || function ( filename ) {
21- // UglifyJs only applies to javascript
22- return ! / \. j s ( $ | \? ) / i. test ( filename ) ;
23- } ;
21+ var that = this ;
22+ options . test = options . test || / \. j s ( $ | \? ) / i;
23+
2424 var requestShortener = new RequestShortener ( compiler . context ) ;
2525 compiler . plugin ( "compilation" , function ( compilation ) {
2626 compilation . plugin ( "build-module" , function ( module ) {
@@ -37,10 +37,8 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
3737 compilation . additionalChunkAssets . forEach ( function ( file ) {
3838 files . push ( file ) ;
3939 } ) ;
40+ files = files . filter ( that . matchObject . bind ( that , options ) ) ;
4041 files . forEach ( function ( file ) {
41- if ( skipFile ( file ) ) {
42- return ;
43- }
4442 var oldWarnFunction = uglify . AST_Node . warn_function ;
4543 var warnings = [ ] ;
4644 try {
@@ -120,4 +118,31 @@ UglifyJsPlugin.prototype.apply = function(compiler) {
120118 context . minimize = true ;
121119 } ) ;
122120 } ) ;
123- } ;
121+ } ;
122+
123+ function asRegExp ( test ) {
124+ if ( typeof test == "string" ) test = new RegExp ( "^" + test . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ) ;
125+ return test ;
126+ }
127+
128+ UglifyJsPlugin . prototype . matchPart = function matchPart ( str , test ) {
129+ if ( ! test ) return true ;
130+ test = asRegExp ( test ) ;
131+ if ( Array . isArray ( test ) ) {
132+ return test . map ( asRegExp ) . filter ( function ( regExp ) {
133+ return regExp . test ( str ) ;
134+ } ) . length > 0 ;
135+ } else {
136+ return test . test ( str ) ;
137+ }
138+ } ;
139+
140+ UglifyJsPlugin . prototype . matchObject = function matchObject ( obj , str ) {
141+ if ( obj . test )
142+ if ( ! this . matchPart ( str , obj . test ) ) return false ;
143+ if ( obj . include )
144+ if ( ! this . matchPart ( str , obj . include ) ) return false ;
145+ if ( obj . exclude )
146+ if ( this . matchPart ( str , obj . exclude ) ) return false ;
147+ return true ;
148+ } ;
0 commit comments