Skip to content

Commit a549c7a

Browse files
committed
Replace uglifyjs-webpack-plugin by terser-webpack-plugin
1 parent bb11e74 commit a549c7a

File tree

10 files changed

+195
-45
lines changed

10 files changed

+195
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ for a full description of all of the valid browser descriptions.
6969
* The `css-loader` can now be configured by calling `configureCssLoader()`.
7070
#335 thanks to @XWB
7171

72-
* It's not possible to control the `exclude` for Babel so that you can
72+
* It's now possible to control the `exclude` for Babel so that you can
7373
process certain node_modules packages through Babel - use
7474
the new second argument to `configureBabel()` - #401 thanks to
7575
@Lyrkan.
@@ -97,9 +97,9 @@ for a full description of all of the valid browser descriptions.
9797
* Actual lang="sass" no longer works for Vue. However, lang="scss"
9898
continues to work fine.
9999

100-
* uglifyjs-webpack-plugin was upgraded from 0.4.6 to 1.2.5, which
101-
includes using `uglify-es`. If you're using `configureUglifyJsPlugin`(),
102-
the options have changed.
100+
* uglifyjs-webpack-plugin was replaced by terser-webpack-plugin.
101+
If you're using `configureUglifyJsPlugin()`, please switch to
102+
`configureTerserPlugin()` instead.
103103

104104
## 0.20.1
105105

index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,25 @@ class Encore {
203203
}
204204

205205
/**
206-
* Allows you to configure the options passed to the uglifyjs-webpack-plugin.
207-
* A list of available options can be found at https://github.com/webpack-contrib/uglifyjs-webpack-plugin
206+
* Allows you to configure the options passed to the terser-webpack-plugin.
207+
* A list of available options can be found at https://github.com/webpack-contrib/terser-webpack-plugin
208208
*
209209
* For example:
210210
*
211-
* Encore.configureUglifyJsPlugin((options) => {
211+
* Encore.configureTerserPlugin((options) => {
212212
* options.cache = true;
213-
* options.uglifyOptions = {
213+
* options.terserOptions = {
214214
* output: {
215215
* comments: false
216216
* }
217217
* }
218218
* })
219219
*
220-
* @param {function} uglifyJsPluginOptionsCallback
220+
* @param {function} terserPluginOptionsCallback
221221
* @returns {Encore}
222222
*/
223-
configureUglifyJsPlugin(uglifyJsPluginOptionsCallback = () => {}) {
224-
webpackConfig.configureUglifyJsPlugin(uglifyJsPluginOptionsCallback);
223+
configureTerserPlugin(terserPluginOptionsCallback = () => {}) {
224+
webpackConfig.configureTerserPlugin(terserPluginOptionsCallback);
225225

226226
return this;
227227
}
@@ -1145,6 +1145,14 @@ class Encore {
11451145
enableCoffeeScriptLoader() {
11461146
throw new Error('The enableCoffeeScriptLoader() method and CoffeeScript support was removed from Encore due to support problems with Webpack 4. If you are interested in this feature, please submit a pull request!');
11471147
}
1148+
1149+
/**
1150+
* @deprecated
1151+
* @return {void}
1152+
*/
1153+
configureUglifyJsPlugin() {
1154+
throw new Error('The configureUglifyJsPlugin() method was removed from Encore due to uglify-js dropping ES6+ support in its latest version. Please use configureTerserPlugin() instead.');
1155+
}
11481156
}
11491157

11501158
// Proxy the API in order to prevent calls to most of its methods

lib/WebpackConfig.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class WebpackConfig {
109109
this.friendlyErrorsPluginOptionsCallback = () => {};
110110
this.loaderOptionsPluginOptionsCallback = () => {};
111111
this.manifestPluginOptionsCallback = () => {};
112-
this.uglifyJsPluginOptionsCallback = () => {};
112+
this.terserPluginOptionsCallback = () => {};
113113
this.notifierPluginOptionsCallback = () => {};
114114
}
115115

@@ -209,12 +209,12 @@ class WebpackConfig {
209209
this.manifestPluginOptionsCallback = manifestPluginOptionsCallback;
210210
}
211211

212-
configureUglifyJsPlugin(uglifyJsPluginOptionsCallback = () => {}) {
213-
if (typeof uglifyJsPluginOptionsCallback !== 'function') {
214-
throw new Error('Argument 1 to configureUglifyJsPlugin() must be a callback function');
212+
configureTerserPlugin(terserPluginOptionsCallback = () => {}) {
213+
if (typeof terserPluginOptionsCallback !== 'function') {
214+
throw new Error('Argument 1 to configureTerserPlugin() must be a callback function');
215215
}
216216

217-
this.uglifyJsPluginOptionsCallback = uglifyJsPluginOptionsCallback;
217+
this.terserPluginOptionsCallback = terserPluginOptionsCallback;
218218
}
219219

220220
/**

lib/config-generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const versioningPluginUtil = require('./plugins/versioning');
3232
const variableProviderPluginUtil = require('./plugins/variable-provider');
3333
const cleanPluginUtil = require('./plugins/clean');
3434
const definePluginUtil = require('./plugins/define');
35-
const uglifyPluginUtil = require('./plugins/uglify');
35+
const terserPluginUtil = require('./plugins/terser');
3636
const vuePluginUtil = require('./plugins/vue');
3737
const friendlyErrorPluginUtil = require('./plugins/friendly-errors');
3838
const assetOutputDisplay = require('./plugins/asset-output-display');
@@ -388,7 +388,7 @@ class ConfigGenerator {
388388

389389
if (this.webpackConfig.isProduction()) {
390390
optimization.minimizer = [
391-
uglifyPluginUtil(this.webpackConfig)
391+
terserPluginUtil(this.webpackConfig)
392392
];
393393
} else {
394394
// see versioning.js: this gives us friendly module names,

lib/plugins/uglify.js renamed to lib/plugins/terser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99

1010
'use strict';
1111

12-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
12+
const TerserPlugin = require('terser-webpack-plugin');
1313
const applyOptionsCallback = require('../utils/apply-options-callback');
1414

1515
/**
1616
* @param {WebpackConfig} webpackConfig
1717
* @return {object}
1818
*/
1919
module.exports = function(webpackConfig) {
20-
const uglifyJsPluginOptions = {
20+
const terserPluginOptions = {
2121
sourceMap: webpackConfig.useSourceMaps
2222
};
2323

24-
return new UglifyJsPlugin(
25-
applyOptionsCallback(webpackConfig.uglifyJsPluginOptionsCallback, uglifyJsPluginOptions)
24+
return new TerserPlugin(
25+
applyOptionsCallback(webpackConfig.terserPluginOptionsCallback, terserPluginOptions)
2626
);
2727
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"resolve-url-loader": "^2.3.0",
4646
"semver": "^5.5.0",
4747
"style-loader": "^0.21.0",
48+
"terser-webpack-plugin": "^1.1.0",
4849
"tmp": "^0.0.33",
49-
"uglifyjs-webpack-plugin": "^1.2.5",
5050
"webpack": "^4.20.0",
5151
"webpack-chunk-hash": "^0.6.0",
5252
"webpack-cli": "^3.0.0",

test/WebpackConfig.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,21 @@ describe('WebpackConfig object', () => {
281281
});
282282
});
283283

284-
describe('configureUglifyJsPlugin', () => {
284+
describe('configureTerserPlugin', () => {
285285
it('Setting callback', () => {
286286
const config = createConfig();
287287
const callback = () => {};
288-
config.configureUglifyJsPlugin(callback);
288+
config.configureTerserPlugin(callback);
289289

290-
expect(config.uglifyJsPluginOptionsCallback).to.equal(callback);
290+
expect(config.terserPluginOptionsCallback).to.equal(callback);
291291
});
292292

293293
it('Setting invalid callback argument', () => {
294294
const config = createConfig();
295295

296296
expect(() => {
297-
config.configureUglifyJsPlugin('foo');
298-
}).to.throw('Argument 1 to configureUglifyJsPlugin() must be a callback function');
297+
config.configureTerserPlugin('foo');
298+
}).to.throw('Argument 1 to configureTerserPlugin() must be a callback function');
299299
});
300300
});
301301

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ describe('Public API', () => {
396396

397397
});
398398

399-
describe('configureUglifyJsPlugin', () => {
399+
describe('configureTerserPlugin', () => {
400400

401401
it('should return the API object', () => {
402-
const returnedValue = api.configureUglifyJsPlugin(() => {});
402+
const returnedValue = api.configureTerserPlugin(() => {});
403403
expect(returnedValue).to.equal(api);
404404
});
405405

test/plugins/uglify.js renamed to test/plugins/terser.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
'use strict';
1111

1212
const expect = require('chai').expect;
13-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
13+
const TerserPlugin = require('terser-webpack-plugin');
1414
const WebpackConfig = require('../../lib/WebpackConfig');
1515
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
16-
const uglifyPluginUtil = require('../../lib/plugins/uglify');
16+
const terserPluginUtil = require('../../lib/plugins/terser');
1717

1818
function createConfig(environment = 'production') {
1919
const runtimeConfig = new RuntimeConfig();
@@ -24,28 +24,28 @@ function createConfig(environment = 'production') {
2424
return new WebpackConfig(runtimeConfig);
2525
}
2626

27-
describe('plugins/uglify', () => {
27+
describe('plugins/terser', () => {
2828
it('production environment default settings', () => {
2929
const config = createConfig();
3030

31-
const plugin = uglifyPluginUtil(config);
32-
expect(plugin).to.be.instanceof(UglifyJsPlugin);
31+
const plugin = terserPluginUtil(config);
32+
expect(plugin).to.be.instanceof(TerserPlugin);
3333
expect(plugin.options.sourceMap).to.equal(false);
3434
});
3535

3636
it('with options callback', () => {
3737
const config = createConfig();
3838

39-
config.configureUglifyJsPlugin((options) => {
40-
options.uglifyOptions = {
39+
config.configureTerserPlugin((options) => {
40+
options.terserOptions = {
4141
output: { beautify: true }
4242
};
4343
});
4444

45-
const plugin = uglifyPluginUtil(config);
45+
const plugin = terserPluginUtil(config);
4646

4747
// Allows to override default options
48-
expect(plugin.options.uglifyOptions.output.beautify).to.equal(true);
48+
expect(plugin.options.terserOptions.output.beautify).to.equal(true);
4949

5050
// Doesn't remove default options
5151
expect(plugin.options.sourceMap).to.equal(false);
@@ -54,17 +54,17 @@ describe('plugins/uglify', () => {
5454
it('with options callback that returns an object', () => {
5555
const config = createConfig();
5656

57-
config.configureUglifyJsPlugin((options) => {
58-
options.uglifyOptions = {
57+
config.configureTerserPlugin((options) => {
58+
options.terserOptions = {
5959
output: { beautify: true }
6060
};
6161

6262
// This should override the original config
6363
return { cache: true };
6464
});
6565

66-
const plugin = uglifyPluginUtil(config);
67-
expect(plugin.options.uglifyOptions.output.beautify).to.be.undefined;
66+
const plugin = terserPluginUtil(config);
67+
expect(plugin.options.terserOptions.output.beautify).to.be.undefined;
6868
expect(plugin.options.cache).to.equal(true);
6969
});
7070
});

0 commit comments

Comments
 (0)