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

Commit d9f4e24

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

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-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)?)(\?[a-z0-9]+)?$/i,
2424
warningsFilter = () => true,
2525
extractComments = false,
2626
sourceMap = false,

test/__snapshots__/test.test.js.snap

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`empty option: errors 1`] = `Array []`;
4+
5+
exports[`empty option: importExport.js?var=c3528f4503928cc8accd 1`] = `"webpackJsonp([0],[,,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]);"`;
6+
7+
exports[`empty option: js.js?var=c3528f4503928cc8accd 1`] = `"webpackJsonp([2],[function(o,n){o.exports=function(){console.log(7)}}],[0]);"`;
8+
9+
exports[`empty option: manifest.js?var=c3528f4503928cc8accd 1`] = `"!function(e){var r=window.webpackJsonp;window.webpackJsonp=function(n,c,i){for(var u,a,f,s=0,p=[];s<n.length;s++)a=n[s],t[a]&&p.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);p.length;)p.shift()();if(i)for(s=0;s<i.length;s++)f=o(o.s=i[s]);return f};var n={},t={3: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+\\".\\"+({0:\\"importExport\\",1:\\"mjs\\",2:\\"js\\"}[e]||e)+\\".js?ver=c3528f4503928cc8accd\\";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}}([]);"`;
10+
11+
exports[`empty option: mjs.js?var=c3528f4503928cc8accd 1`] = `"webpackJsonp([1],[,function(o,n){o.exports=function(){console.log(7)}}],[1]);"`;
12+
13+
exports[`empty option: warnings 1`] = `Array []`;

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+
};

test/test.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
},
16+
output: {
17+
path: `${__dirname}/dist`,
18+
filename: '[name].js?var=[hash]',
19+
chunkFilename: '[id].[name].js?ver=[hash]',
20+
},
21+
});
22+
23+
new UglifyJsPlugin().apply(compiler);
24+
25+
return compile(compiler).then((stats) => {
26+
const errors = stats.compilation.errors.map(cleanErrorStack);
27+
const warnings = stats.compilation.warnings.map(cleanErrorStack);
28+
29+
expect(errors).toMatchSnapshot('empty option: errors');
30+
expect(warnings).toMatchSnapshot('empty option: warnings');
31+
32+
for (const file in stats.compilation.assets) {
33+
if (Object.prototype.hasOwnProperty.call(stats.compilation.assets, file)) {
34+
expect(stats.compilation.assets[file].source()).toMatchSnapshot(`empty option: ${file}`);
35+
}
36+
}
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)