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

Commit 424d7af

Browse files
author
evilebottnawi
committed
fix: handle files with query params
1 parent 14d2c4c commit 424d7af

File tree

7 files changed

+74
-1
lines changed

7 files changed

+74
-1
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class UglifyJsPlugin {
2020

2121
const {
2222
uglifyOptions = {},
23-
test = /\.js$/i,
23+
test = /\.(js?)(\?.+)?$/i,
2424
warningsFilter = () => true,
2525
extractComments = false,
2626
sourceMap = false,

test/__snapshots__/test.test.js.snap

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`empty option: 0.0.js?ver=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([0],{5:function(e,t,c){\\"use strict\\";Object.defineProperty(t,\\"__esModule\\",{value:!0}),t.default=\\"async-dep\\"}});"`;
4+
5+
exports[`empty option: AsyncImportExport.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([4],{4:function(e,o,n){\\"use strict\\";Object.defineProperty(o,\\"__esModule\\",{value:!0}),n.e(0).then(n.bind(null,5)).then(()=>{console.log(\\"Good\\")}),o.default=\\"Awesome\\"}},[4]);"`;
6+
7+
exports[`empty option: errors 1`] = `Array []`;
8+
9+
exports[`empty option: importExport.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([1],[,,function(t,a,e){\\"use strict\\";Object.defineProperty(a,\\"__esModule\\",{value:!0});var n=e(3);a.default=function(){const t=n.b,a=\`baz\${Math.random()}\`;return()=>({a:t+n.a+a,b:t,baz:a})}},function(t,a,e){\\"use strict\\";a.a=\\"bar\\",a.b=\\"foo\\"}],[2]);"`;
10+
11+
exports[`empty option: js.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([3],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`;
12+
13+
exports[`empty option: manifest.js?var=bd0395a3b5883cc6e11c 1`] = `"!function(e){var r=window.webpackJsonp;window.webpackJsonp=function(n,c,i){for(var u,a,p,s=0,f=[];s<n.length;s++)a=n[s],t[a]&&f.push(t[a][0]),t[a]=0;for(u in c)Object.prototype.hasOwnProperty.call(c,u)&&(e[u]=c[u]);for(r&&r(n,c,i);f.length;)f.shift()();if(i)for(s=0;s<i.length;s++)p=o(o.s=i[s]);return p};var n={},t={5:0};function o(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.e=function(e){var r=t[e];if(0===r)return new Promise(function(e){e()});if(r)return r[2];var n=new Promise(function(n,o){r=t[e]=[n,o]});r[2]=n;var c=document.getElementsByTagName(\\"head\\")[0],i=document.createElement(\\"script\\");i.type=\\"text/javascript\\",i.charset=\\"utf-8\\",i.async=!0,i.timeout=12e4,o.nc&&i.setAttribute(\\"nonce\\",o.nc),i.src=o.p+\\"\\"+e+\\".\\"+({1:\\"importExport\\",2:\\"mjs\\",3:\\"js\\",4:\\"AsyncImportExport\\"}[e]||e)+\\".js?ver=bd0395a3b5883cc6e11c\\";var u=setTimeout(a,12e4);function a(){i.onerror=i.onload=null,clearTimeout(u);var r=t[e];0!==r&&(r&&r[1](new Error(\\"Loading chunk \\"+e+\\" failed.\\")),t[e]=void 0)}return i.onerror=i.onload=a,c.appendChild(i),n},o.m=e,o.c=n,o.d=function(e,r,n){o.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},o.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(r,\\"a\\",r),r},o.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},o.p=\\"\\",o.oe=function(e){throw console.error(e),e}}([]);"`;
14+
15+
exports[`empty option: mjs.js?var=bd0395a3b5883cc6e11c 1`] = `"webpackJsonp([2],[,function(o,n){o.exports=function(){console.log(7)}}],[1]);"`;
16+
17+
exports[`empty option: warnings 1`] = `Array []`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "async-dep";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import("./async-dep").then(() => {
2+
console.log('Good')
3+
});
4+
5+
export default "Awesome";

test/fixtures/entry.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// foo
2+
/* @preserve*/
3+
// bar
4+
const a = 2 + 2;
5+
6+
module.exports = function Foo() {
7+
const b = 2 + 2;
8+
console.log(b + 1 + 2);
9+
};
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "async-dep";

test/test.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import UglifyJsPlugin from '../src/index';
2+
import {
3+
cleanErrorStack,
4+
createCompiler,
5+
compile,
6+
} from './helpers';
7+
8+
describe('when applied with test option', () => {
9+
it('with empty value', () => {
10+
const compiler = createCompiler({
11+
entry: {
12+
js: `${__dirname}/fixtures/entry.js`,
13+
mjs: `${__dirname}/fixtures/entry.mjs`,
14+
importExport: `${__dirname}/fixtures/import-export/entry.js`,
15+
AsyncImportExport: `${__dirname}/fixtures/async-import-export/entry.js`,
16+
},
17+
output: {
18+
path: `${__dirname}/dist`,
19+
filename: '[name].js?var=[hash]',
20+
chunkFilename: '[id].[name].js?ver=[hash]',
21+
},
22+
});
23+
24+
new UglifyJsPlugin().apply(compiler);
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('empty option: errors');
31+
expect(warnings).toMatchSnapshot('empty option: 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(`empty option: ${file}`);
36+
}
37+
}
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)