Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit ad17690

Browse files
rszewczykmichael-ciniawsky
authored andcommitted
fix(index): exclude is ignored (options.exclude) (#164)
1 parent c425f3c commit ad17690

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

Diff for: src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class UglifyJsPlugin {
3131
sourceMap = false,
3232
cache = false,
3333
parallel = false,
34+
exclude,
3435
} = options;
3536

3637
this.options = {
@@ -40,6 +41,7 @@ class UglifyJsPlugin {
4041
sourceMap,
4142
cache,
4243
parallel,
44+
exclude,
4345
uglifyOptions: {
4446
output: {
4547
comments: /^\**!|@preserve|@license|@cc_on/,

Diff for: test/__snapshots__/exclude-option.test.js.snap

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`errors 1`] = `Array []`;
4+
5+
exports[`errors 2`] = `Array []`;
6+
7+
exports[`excluded1.4d3a1b43eccbc2acc9d6.js 1`] = `
8+
"webpackJsonp([1],[
9+
/* 0 */
10+
/***/ (function(module, exports) {
11+
12+
module.exports = function Bar1() {
13+
const b = 2 + 2;
14+
console.log(b + 1 + 2);
15+
};
16+
17+
/***/ })
18+
],[0]);"
19+
`;
20+
21+
exports[`excluded1.4d3a1b43eccbc2acc9d6.js 2`] = `
22+
"webpackJsonp([1],[
23+
/* 0 */
24+
/***/ (function(module, exports) {
25+
26+
module.exports = function Bar1() {
27+
const b = 2 + 2;
28+
console.log(b + 1 + 2);
29+
};
30+
31+
/***/ })
32+
],[0]);"
33+
`;
34+
35+
exports[`excluded2.a96f544a34079b25c7b4.js 1`] = `"webpackJsonp([0],[,function(o,n){o.exports=function(){console.log(7)}}],[1]);"`;
36+
37+
exports[`excluded2.a96f544a34079b25c7b4.js 2`] = `
38+
"webpackJsonp([0],[
39+
/* 0 */,
40+
/* 1 */
41+
/***/ (function(module, exports) {
42+
43+
module.exports = function Bar2() {
44+
const b = 2 + 2;
45+
console.log(b + 1 + 2);
46+
};
47+
48+
/***/ })
49+
],[1]);"
50+
`;
51+
52+
exports[`included.97bcf4abdd9efecc94b3.js 1`] = `"webpackJsonp([2],{2:function(o,n){o.exports=function(){console.log(7)}}},[2]);"`;
53+
54+
exports[`included.97bcf4abdd9efecc94b3.js 2`] = `"webpackJsonp([2],{2:function(o,n){o.exports=function(){console.log(7)}}},[2]);"`;
55+
56+
exports[`manifest.2264c6ca1c158d5cd90e.js 1`] = `"!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,a){for(var u,i,f,l=0,d=[];l<t.length;l++)i=t[l],o[i]&&d.push(o[i][0]),o[i]=0;for(u in c)Object.prototype.hasOwnProperty.call(c,u)&&(e[u]=c[u]);for(r&&r(t,c,a);d.length;)d.shift()();if(a)for(l=0;l<a.length;l++)f=n(n.s=a[l]);return f};var t={},o={3:0};n.e=function(e){function r(){u.onerror=u.onload=null,clearTimeout(i);var n=o[e];0!==n&&(n&&n[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var a=document.getElementsByTagName(\\"head\\")[0],u=document.createElement(\\"script\\");u.type=\\"text/javascript\\",u.charset=\\"utf-8\\",u.async=!0,u.timeout=12e4,n.nc&&u.setAttribute(\\"nonce\\",n.nc),u.src=n.p+\\"\\"+e+\\".\\"+({0:\\"excluded2\\",1:\\"excluded1\\",2:\\"included\\"}[e]||e)+\\".\\"+{0:\\"a96f544a34079b25c7b4\\",1:\\"4d3a1b43eccbc2acc9d6\\",2:\\"97bcf4abdd9efecc94b3\\"}[e]+\\".js\\";var i=setTimeout(r,12e4);return u.onerror=u.onload=r,a.appendChild(u),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,\\"a\\",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p=\\"\\",n.oe=function(e){throw console.error(e),e}}([]);"`;
57+
58+
exports[`manifest.2264c6ca1c158d5cd90e.js 2`] = `"!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,a){for(var u,i,f,l=0,d=[];l<t.length;l++)i=t[l],o[i]&&d.push(o[i][0]),o[i]=0;for(u in c)Object.prototype.hasOwnProperty.call(c,u)&&(e[u]=c[u]);for(r&&r(t,c,a);d.length;)d.shift()();if(a)for(l=0;l<a.length;l++)f=n(n.s=a[l]);return f};var t={},o={3:0};n.e=function(e){function r(){u.onerror=u.onload=null,clearTimeout(i);var n=o[e];0!==n&&(n&&n[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var a=document.getElementsByTagName(\\"head\\")[0],u=document.createElement(\\"script\\");u.type=\\"text/javascript\\",u.charset=\\"utf-8\\",u.async=!0,u.timeout=12e4,n.nc&&u.setAttribute(\\"nonce\\",n.nc),u.src=n.p+\\"\\"+e+\\".\\"+({0:\\"excluded2\\",1:\\"excluded1\\",2:\\"included\\"}[e]||e)+\\".\\"+{0:\\"a96f544a34079b25c7b4\\",1:\\"4d3a1b43eccbc2acc9d6\\",2:\\"97bcf4abdd9efecc94b3\\"}[e]+\\".js\\";var i=setTimeout(r,12e4);return u.onerror=u.onload=r,a.appendChild(u),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,\\"a\\",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p=\\"\\",n.oe=function(e){throw console.error(e),e}}([]);"`;
59+
60+
exports[`warnings 1`] = `Array []`;
61+
62+
exports[`warnings 2`] = `Array []`;

Diff for: test/exclude-option.test.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import UglifyJsPlugin from '../src/index';
2+
import {
3+
cleanErrorStack,
4+
createCompiler,
5+
compile,
6+
} from './helpers';
7+
8+
describe('when applied with exclude option', () => {
9+
let compiler;
10+
beforeEach(() => {
11+
compiler = createCompiler({
12+
entry: {
13+
excluded1: `${__dirname}/fixtures/excluded1.js`,
14+
excluded2: `${__dirname}/fixtures/excluded2.js`,
15+
included: `${__dirname}/fixtures/entry.js`,
16+
},
17+
});
18+
});
19+
20+
it('matches snapshot for a single exclude', () => {
21+
new UglifyJsPlugin({
22+
exclude: /excluded1/,
23+
}).apply(compiler);
24+
25+
26+
return compile(compiler).then((stats) => {
27+
const errors = stats.compilation.errors.map(cleanErrorStack);
28+
const warnings = stats.compilation.warnings.map(cleanErrorStack);
29+
30+
expect(errors).toMatchSnapshot('errors');
31+
expect(warnings).toMatchSnapshot('warnings');
32+
33+
for (const file in stats.compilation.assets) {
34+
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
35+
expect(stats.compilation.assets[file].source()).toMatchSnapshot(file);
36+
}
37+
}
38+
});
39+
});
40+
41+
it('matches snapshot for multiple excludes', () => {
42+
new UglifyJsPlugin({
43+
exclude: [
44+
/excluded1/,
45+
/excluded2/,
46+
],
47+
}).apply(compiler);
48+
49+
50+
return compile(compiler).then((stats) => {
51+
const errors = stats.compilation.errors.map(cleanErrorStack);
52+
const warnings = stats.compilation.warnings.map(cleanErrorStack);
53+
54+
expect(errors).toMatchSnapshot('errors');
55+
expect(warnings).toMatchSnapshot('warnings');
56+
57+
for (const file in stats.compilation.assets) {
58+
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
59+
expect(stats.compilation.assets[file].source()).toMatchSnapshot(file);
60+
}
61+
}
62+
});
63+
});
64+
});

Diff for: test/fixtures/excluded1.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function Bar1() {
2+
const b = 2 + 2;
3+
console.log(b + 1 + 2);
4+
};

Diff for: test/fixtures/excluded2.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function Bar2() {
2+
const b = 2 + 2;
3+
console.log(b + 1 + 2);
4+
};

0 commit comments

Comments
 (0)