From 86731cc5b3c678844605b60c7247ae424b07125a Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Thu, 14 Jun 2018 06:56:56 +0200 Subject: [PATCH] change Uglify to Terser (#1382) --- package.json | 23 +++++++++-------------- src/assets/JSAsset.js | 4 ++-- src/assets/JSONAsset.js | 2 +- src/assets/VueAsset.js | 2 +- src/transforms/{uglify.js => terser.js} | 4 ++-- src/utils/serializeObject.js | 2 +- yarn.lock | 13 ++++++++++++- 7 files changed, 28 insertions(+), 22 deletions(-) rename src/transforms/{uglify.js => terser.js} (92%) diff --git a/package.json b/package.json index 0a1f1773e67..7d90846c7bc 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,7 @@ "type": "git", "url": "https://github.com/parcel-bundler/parcel.git" }, - "files": [ - "bin/", - "lib/", - "src/", - "index.js" - ], + "files": ["bin/", "lib/", "src/", "index.js"], "dependencies": { "ansi-to-html": "^0.6.4", "babel-code-frame": "^6.26.0", @@ -64,7 +59,7 @@ "strip-ansi": "^4.0.0", "toml": "^2.3.3", "tomlify-j0.4": "^3.0.0", - "uglify-es": "^3.2.1", + "terser": "^3.7.3", "v8-compile-cache": "^2.0.0", "ws": "^5.1.1" }, @@ -111,10 +106,13 @@ "format": "prettier --write \"./{src,bin,test}/**/*.{js,json,md}\"", "build": "yarn minify && babel src -d lib && ncp src/builtins lib/builtins", "prepublish": "yarn build", - "minify": "uglifyjs -c -m -o src/builtins/prelude.min.js src/builtins/prelude.js", + "minify": + "terser -c -m -o src/builtins/prelude.min.js src/builtins/prelude.js", "precommit": "npm run lint && lint-staged", - "lint": "eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different", - "postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\"" + "lint": + "eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different", + "postinstall": + "node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\"" }, "bin": { "parcel": "bin/cli.js" @@ -123,10 +121,7 @@ "node": ">= 6.0.0" }, "lint-staged": { - "*.{js,json,md}": [ - "prettier --write", - "git add" - ] + "*.{js,json,md}": ["prettier --write", "git add"] }, "collective": { "type": "opencollective", diff --git a/src/assets/JSAsset.js b/src/assets/JSAsset.js index 55220ff739a..cfdc370fe0e 100644 --- a/src/assets/JSAsset.js +++ b/src/assets/JSAsset.js @@ -10,7 +10,7 @@ const fsVisitor = require('../visitors/fs'); const envVisitor = require('../visitors/env'); const babel = require('../transforms/babel'); const generate = require('babel-generator').default; -const uglify = require('../transforms/uglify'); +const terser = require('../transforms/terser'); const SourceMap = require('../SourceMap'); const IMPORT_RE = /\b(?:import\b|export\b|require\s*\()/; @@ -128,7 +128,7 @@ class JSAsset extends Asset { } if (this.options.minify) { - await uglify(this); + await terser(this); } } diff --git a/src/assets/JSONAsset.js b/src/assets/JSONAsset.js index bc652b59814..2979b7e1d31 100644 --- a/src/assets/JSONAsset.js +++ b/src/assets/JSONAsset.js @@ -1,7 +1,7 @@ const Asset = require('../Asset'); const path = require('path'); const json5 = require('json5'); -const {minify} = require('uglify-es'); +const {minify} = require('terser'); class JSONAsset extends Asset { constructor(name, options) { diff --git a/src/assets/VueAsset.js b/src/assets/VueAsset.js index 4c78312b9c7..a5705dcebde 100644 --- a/src/assets/VueAsset.js +++ b/src/assets/VueAsset.js @@ -1,7 +1,7 @@ const Asset = require('../Asset'); const localRequire = require('../utils/localRequire'); const md5 = require('../utils/md5'); -const {minify} = require('uglify-es'); +const {minify} = require('terser'); class VueAsset extends Asset { constructor(name, options) { diff --git a/src/transforms/uglify.js b/src/transforms/terser.js similarity index 92% rename from src/transforms/uglify.js rename to src/transforms/terser.js index 7a902720223..b9ae9295827 100644 --- a/src/transforms/uglify.js +++ b/src/transforms/terser.js @@ -1,4 +1,4 @@ -const {minify} = require('uglify-es'); +const {minify} = require('terser'); const SourceMap = require('../SourceMap'); module.exports = async function(asset) { @@ -7,7 +7,7 @@ module.exports = async function(asset) { // Convert AST into JS let source = (await asset.generate()).js; - let customConfig = await asset.getConfig(['.uglifyrc']); + let customConfig = await asset.getConfig(['.uglifyrc', '.terserrc']); let options = { warnings: true, mangle: { diff --git a/src/utils/serializeObject.js b/src/utils/serializeObject.js index 3dd4825debe..eca913aa5d1 100644 --- a/src/utils/serializeObject.js +++ b/src/utils/serializeObject.js @@ -1,4 +1,4 @@ -const {minify} = require('uglify-es'); +const {minify} = require('terser'); const {serialize} = require('serialize-to-js'); function serializeObject(obj, shouldMinify = false) { diff --git a/yarn.lock b/yarn.lock index 6550c5c8f36..ad7bb0e8052 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1447,6 +1447,10 @@ commander@~2.13.0: version "2.13.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" +commander@~2.14.1: + version "2.14.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" + commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" @@ -6518,6 +6522,13 @@ tar@^4: safe-buffer "^5.1.2" yallist "^3.0.2" +terser@^3.7.3: + version "3.7.3" + resolved "https://registry.yarnpkg.com/terser/-/terser-3.7.3.tgz#e2b6a38f989e4fe46630d4858d184b76ce34883a" + dependencies: + commander "~2.14.1" + source-map "~0.6.1" + test-exclude@^4.2.0: version "4.2.1" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.2.1.tgz#dfa222f03480bca69207ca728b37d74b45f724fa" @@ -6678,7 +6689,7 @@ typescript@^2.7.0: version "2.8.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170" -uglify-es@^3.2.1, uglify-es@^3.3.9: +uglify-es@^3.3.9: version "3.3.9" resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677" dependencies: