Skip to content

Commit

Permalink
Make metro-minify-terser the default minifier (#871)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #871

`uglify-es` has not been published for 4 years and is marked deprecated [on npm](https://www.npmjs.com/package/uglify-es). Increasingly it does not support syntax that we would otherwise be able to pass through untranspiled.

`terser` is a fork of `uglify-es` that is currently the most downloaded JS minifier ([`terser`](https://www.npmjs.com/package/terser) vs [`uglify-js`](https://www.npmjs.com/package/uglify-js)). It's well-maintained and the common ancestry with `uglify-es`, including very similar configuration options, minimise risk for Metro users. At the same time, it aims to support features right up to Stage 4 proposals.

Changelog:
**[Breaking]** Switch default minifier from `uglify-es` to `terser`

Reviewed By: huntie

Differential Revision: D34647616

fbshipit-source-id: 1ecca5d40bc3ab637303efa541163258f5a42f28
  • Loading branch information
robhogan authored and facebook-github-bot committed Sep 20, 2022
1 parent e241d8a commit 44355fd
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ Use the hermes-parser package to use call Hermes parser via WASM instead of the

#### `minifierPath`

Type: `string`
Type: `string` (default: `'metro-minify-terser'`)

Path to the minifier that minifies the code after transformation.
Path, or package name resolvable from `metro-transform-worker`, to the minifier that minifies the code after transformation.

#### `minifierConfig`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Object {
},
"toplevel": false,
},
"minifierPath": "metro-minify-uglify",
"minifierPath": "metro-minify-terser",
"optimizationSizeLimit": 153600,
"publicPath": "/assets",
"transformVariants": Object {
Expand Down Expand Up @@ -290,7 +290,7 @@ Object {
},
"toplevel": false,
},
"minifierPath": "metro-minify-uglify",
"minifierPath": "metro-minify-terser",
"optimizationSizeLimit": 153600,
"publicPath": "/assets",
"transformVariants": Object {
Expand Down Expand Up @@ -451,7 +451,7 @@ Object {
},
"toplevel": false,
},
"minifierPath": "metro-minify-uglify",
"minifierPath": "metro-minify-terser",
"optimizationSizeLimit": 153600,
"publicPath": "/assets",
"transformVariants": Object {
Expand Down Expand Up @@ -612,7 +612,7 @@ Object {
},
"toplevel": false,
},
"minifierPath": "metro-minify-uglify",
"minifierPath": "metro-minify-terser",
"optimizationSizeLimit": 153600,
"publicPath": "/assets",
"transformVariants": Object {
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-config/src/defaults/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ exports.moduleSystem = (require.resolve(

exports.platforms = ['ios', 'android', 'windows', 'web'];

exports.DEFAULT_METRO_MINIFIER_PATH = 'metro-minify-uglify';
exports.DEFAULT_METRO_MINIFIER_PATH = 'metro-minify-terser';

exports.defaultCreateModuleIdFactory = defaultCreateModuleIdFactory;
2 changes: 1 addition & 1 deletion packages/metro-minify-terser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"license": "MIT",
"dependencies": {
"terser": "^5.14.0"
"terser": "^5.15.0"
}
}
2 changes: 1 addition & 1 deletion packages/metro-transform-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"devDependencies": {
"metro-memory-fs": "0.72.3",
"metro-minify-uglify": "0.72.3",
"metro-minify-terser": "0.72.3",
"metro-react-native-babel-transformer": "0.72.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest
inlinePlugin: () => ({}),
constantFoldingPlugin: () => ({}),
}))
.mock('metro-minify-uglify');
.mock('metro-minify-terser');

import type {JsTransformerConfig} from '../index';
import typeof TransformerType from '../index';
Expand Down
1 change: 1 addition & 0 deletions packages/metro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"metro-file-map": "0.72.3",
"metro-hermes-compiler": "0.72.3",
"metro-inspector-proxy": "0.72.3",
"metro-minify-terser": "0.72.3",
"metro-minify-uglify": "0.72.3",
"metro-react-native-babel-preset": "0.72.3",
"metro-resolver": "0.72.3",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7845,10 +7845,10 @@ terminal-link@^2.0.0:
ansi-escapes "^4.2.1"
supports-hyperlinks "^2.0.0"

terser@^5.14.0:
version "5.14.2"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.14.2.tgz#9ac9f22b06994d736174f4091aa368db896f1c10"
integrity sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==
terser@^5.15.0:
version "5.15.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.15.0.tgz#e16967894eeba6e1091509ec83f0c60e179f2425"
integrity sha512-L1BJiXVmheAQQy+as0oF3Pwtlo4s3Wi1X2zNZ2NxOB4wx9bdS9Vk67XQENLFdLYGCK/Z2di53mTj/hBafR+dTA==
dependencies:
"@jridgewell/source-map" "^0.3.2"
acorn "^8.5.0"
Expand Down

0 comments on commit 44355fd

Please sign in to comment.