Skip to content

Commit 21da35f

Browse files
abenezerabebesendilkumarn
authored andcommitted
ast: replace UglifyJsPlugin with TerserPlugin
if a module requires uglify-js-plugin, replace it with a require for terser-webpack-plugin
1 parent 9863445 commit 21da35f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

packages/migrate/uglifyJsPlugin/__snapshots__/uglifyJsPlugin.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-3" data 1`] =
7878
`;
7979

8080
exports[`uglifyJsPlugin transforms correctly using "uglifyJsPlugin-4" data 1`] = `
81-
"const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
81+
"const TerserPlugin = require('terser-webpack-plugin');
8282
module.exports = {
8383
devtool: 'eval',
8484
@@ -110,7 +110,7 @@ module.exports = {
110110
optimization: {
111111
minimize: true,
112112
113-
minimizer: [new UglifyJsPlugin({
113+
minimizer: [new TerserPlugin({
114114
sourceMap: true
115115
})]
116116
}

packages/migrate/uglifyJsPlugin/uglifyJsPlugin.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { IJSCodeshift, INode } from "../types/NodePath";
1515
* and adds `optimization.minimize: true` to config
1616
*
1717
* If any configuration is passed to UglifyWebpackPlugin
18-
* plugin instantiation is moved to `optimization.minimizer`.
18+
* Replaces UglifyWebpackPlugin with TerserPlugin and
19+
* and moves plugin instantiation to `optimization.minimizer`.
1920
*
2021
* @param {Object} j - jscodeshift top-level import
2122
* @param {Node} ast - jscodeshift ast to transform
@@ -63,15 +64,15 @@ export default function(j: IJSCodeshift, ast: INode): INode {
6364
* If user is using UglifyJsPlugin directly from webpack
6465
* transformation must:
6566
* - remove it
66-
* - add require for uglify-webpack-plugin
67+
* - add require for terser-webpack-plugin
6768
* - add to minimizer
6869
*/
6970
if (pluginVariableAssignment && pluginVariableAssignment.includes("webpack")) {
70-
// create require for uglify-webpack-plugin
71+
// create require for terser-webpack-plugin
7172
const pathRequire: INode = getRequire(
7273
j,
73-
"UglifyJsPlugin",
74-
"uglifyjs-webpack-plugin",
74+
"TerserPlugin",
75+
"terser-webpack-plugin",
7576
);
7677
// append to source code.
7778
ast
@@ -84,7 +85,7 @@ export default function(j: IJSCodeshift, ast: INode): INode {
8485
"init",
8586
j.identifier("minimizer"),
8687
j.arrayExpression([
87-
j.newExpression(j.identifier("UglifyJsPlugin"), [pluginOptions[0]]),
88+
j.newExpression(j.identifier("TerserPlugin"), [pluginOptions[0]]),
8889
]),
8990
);
9091
} else {

0 commit comments

Comments
 (0)