Repository: webpack-contrib/uglifyjs-webpack-plugin
Pull request #163 (2017-11-13 19:33:22)

docs(README): rename `UglifyJSPlugin` to `UglifyJsPlugin` in examples
The code samples in the README refer to the plugin as `UglifyJSPlugin` instead of `UglifyJsPlugin` which is incorrect (see export [here](https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/master/src/index.js#L246). This PR fixes the README.

jsf-clabot: [![CLA assistant check](https://cla.js.foundation/pull/badge/not_signed)](https://cla.js.foundation/webpack-contrib/uglifyjs-webpack-plugin?pullRequest=163) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla.js.foundation/webpack-contrib/uglifyjs-webpack-plugin?pullRequest=163) before we can accept your contribution.<br/>

Patch:
diff --git a/README.md b/README.md
index 5dc0e8c..f806875 100644
--- a/README.md
+++ b/README.md
@@ -27,11 +27,11 @@ npm i -D uglifyjs-webpack-plugin
 
 **webpack.config.js**
 ```js
-const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
 
 module.exports = {
   plugins: [
-    new UglifyJSPlugin()
+    new UglifyJsPlugin()
   ]
 }
 ```
@@ -55,7 +55,7 @@ module.exports = {
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     test: /\.js($|\?)/i
   })
 ]
@@ -66,7 +66,7 @@ module.exports = {
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     include: /\/includes/
   })
 ]
@@ -77,7 +77,7 @@ module.exports = {
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     exclude: /\/excludes/
   })
 ]
@@ -90,7 +90,7 @@ module.exports = {
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     cache: true
   })
 ]
@@ -104,7 +104,7 @@ Default path to cache directory: `node_modules/.cache/uglifyjs-webpack-plugin`.
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     cache: 'path/to/cache'
   })
 ]
@@ -119,7 +119,7 @@ Path to cache directory.
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     parallel: true
   })
 ]
@@ -133,7 +133,7 @@ Default number of concurrent runs: `os.cpus().length - 1`.
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     parallel: 4
   })
 ]
@@ -148,7 +148,7 @@ Number of concurrent runs.
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     sourceMap: true
   })
 ]
@@ -171,7 +171,7 @@ Number of concurrent runs.
 **webpack.config.js**
 ```js
 [
-  new UglifyJSPlugin({
+  new UglifyJsPlugin({
     uglifyOptions: {
       ie8: false,
       ecma: 8,
diff --git a/src/index.js b/src/index.js
index 4d7a0e6..911e1b4 100644
--- a/src/index.js
+++ b/src/index.js
@@ -31,6 +31,7 @@ class UglifyJsPlugin {
       sourceMap = false,
       cache = false,
       parallel = false,
+      exclude,
     } = options;
 
     this.options = {
@@ -40,6 +41,7 @@ class UglifyJsPlugin {
       sourceMap,
       cache,
       parallel,
+      exclude,
       uglifyOptions: {
         output: {
           comments: /^\**!|@preserve|@license|@cc_on/,


Test patch:
diff --git a/test/__snapshots__/exclude-option.test.js.snap b/test/__snapshots__/exclude-option.test.js.snap
new file mode 100644
index 0000000..5c446b5
--- /dev/null
+++ b/test/__snapshots__/exclude-option.test.js.snap
@@ -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 []`;
diff --git a/test/exclude-option.test.js b/test/exclude-option.test.js
new file mode 100644
index 0000000..80ec1fd
--- /dev/null
+++ b/test/exclude-option.test.js
@@ -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);
+        }
+      }
+    });
+  });
+});
diff --git a/test/fixtures/excluded1.js b/test/fixtures/excluded1.js
new file mode 100644
index 0000000..bf81a23
--- /dev/null
+++ b/test/fixtures/excluded1.js
@@ -0,0 +1,4 @@
+module.exports = function Bar1() {
+  const b = 2 + 2;
+  console.log(b + 1 + 2);
+};
\ No newline at end of file
diff --git a/test/fixtures/excluded2.js b/test/fixtures/excluded2.js
new file mode 100644
index 0000000..6bae073
--- /dev/null
+++ b/test/fixtures/excluded2.js
@@ -0,0 +1,4 @@
+module.exports = function Bar2() {
+  const b = 2 + 2;
+  console.log(b + 1 + 2);
+};
\ No newline at end of file