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

Commit

Permalink
fix(index): exclude is ignored (options.exclude) (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
rszewczyk authored and michael-ciniawsky committed Nov 15, 2017
1 parent c425f3c commit ad17690
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class UglifyJsPlugin {
sourceMap = false,
cache = false,
parallel = false,
exclude,
} = options;

this.options = {
Expand All @@ -40,6 +41,7 @@ class UglifyJsPlugin {
sourceMap,
cache,
parallel,
exclude,
uglifyOptions: {
output: {
comments: /^\**!|@preserve|@license|@cc_on/,
Expand Down
62 changes: 62 additions & 0 deletions test/__snapshots__/exclude-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`errors 1`] = `Array []`;

exports[`errors 2`] = `Array []`;

exports[`excluded1.4d3a1b43eccbc2acc9d6.js 1`] = `
"webpackJsonp([1],[
/* 0 */
/***/ (function(module, exports) {
module.exports = function Bar1() {
const b = 2 + 2;
console.log(b + 1 + 2);
};
/***/ })
],[0]);"
`;

exports[`excluded1.4d3a1b43eccbc2acc9d6.js 2`] = `
"webpackJsonp([1],[
/* 0 */
/***/ (function(module, exports) {
module.exports = function Bar1() {
const b = 2 + 2;
console.log(b + 1 + 2);
};
/***/ })
],[0]);"
`;

exports[`excluded2.a96f544a34079b25c7b4.js 1`] = `"webpackJsonp([0],[,function(o,n){o.exports=function(){console.log(7)}}],[1]);"`;

exports[`excluded2.a96f544a34079b25c7b4.js 2`] = `
"webpackJsonp([0],[
/* 0 */,
/* 1 */
/***/ (function(module, exports) {
module.exports = function Bar2() {
const b = 2 + 2;
console.log(b + 1 + 2);
};
/***/ })
],[1]);"
`;

exports[`included.97bcf4abdd9efecc94b3.js 1`] = `"webpackJsonp([2],{2:function(o,n){o.exports=function(){console.log(7)}}},[2]);"`;

exports[`included.97bcf4abdd9efecc94b3.js 2`] = `"webpackJsonp([2],{2:function(o,n){o.exports=function(){console.log(7)}}},[2]);"`;

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}}([]);"`;

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}}([]);"`;

exports[`warnings 1`] = `Array []`;

exports[`warnings 2`] = `Array []`;
64 changes: 64 additions & 0 deletions test/exclude-option.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import UglifyJsPlugin from '../src/index';
import {
cleanErrorStack,
createCompiler,
compile,
} from './helpers';

describe('when applied with exclude option', () => {
let compiler;
beforeEach(() => {
compiler = createCompiler({
entry: {
excluded1: `${__dirname}/fixtures/excluded1.js`,
excluded2: `${__dirname}/fixtures/excluded2.js`,
included: `${__dirname}/fixtures/entry.js`,
},
});
});

it('matches snapshot for a single exclude', () => {
new UglifyJsPlugin({
exclude: /excluded1/,
}).apply(compiler);


return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);

expect(errors).toMatchSnapshot('errors');
expect(warnings).toMatchSnapshot('warnings');

for (const file in stats.compilation.assets) {
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
expect(stats.compilation.assets[file].source()).toMatchSnapshot(file);
}
}
});
});

it('matches snapshot for multiple excludes', () => {
new UglifyJsPlugin({
exclude: [
/excluded1/,
/excluded2/,
],
}).apply(compiler);


return compile(compiler).then((stats) => {
const errors = stats.compilation.errors.map(cleanErrorStack);
const warnings = stats.compilation.warnings.map(cleanErrorStack);

expect(errors).toMatchSnapshot('errors');
expect(warnings).toMatchSnapshot('warnings');

for (const file in stats.compilation.assets) {
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
expect(stats.compilation.assets[file].source()).toMatchSnapshot(file);
}
}
});
});
});
4 changes: 4 additions & 0 deletions test/fixtures/excluded1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function Bar1() {
const b = 2 + 2;
console.log(b + 1 + 2);
};
4 changes: 4 additions & 0 deletions test/fixtures/excluded2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function Bar2() {
const b = 2 + 2;
console.log(b + 1 + 2);
};

0 comments on commit ad17690

Please sign in to comment.