From f3b06eae4e12d5b3e6d8f3ced0c1581b30520f0c Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 8 Nov 2017 00:47:30 +0000 Subject: [PATCH] Replace Uglify with GCC --- package.json | 3 +- scripts/rollup/build.js | 168 ++++++++++++++-------------------------- yarn.lock | 36 +++++---- 3 files changed, 79 insertions(+), 128 deletions(-) diff --git a/package.json b/package.json index 4b42bb5ebdf26..d8d77c57ee4a6 100644 --- a/package.json +++ b/package.json @@ -83,13 +83,12 @@ "rollup-plugin-commonjs": "^8.2.6", "rollup-plugin-inject": "^2.0.0", "rollup-plugin-node-resolve": "^2.0.0", + "rollup-plugin-prettier": "^0.3.0", "rollup-plugin-replace": "^1.1.1", - "rollup-plugin-uglify": "^1.0.1", "run-sequence": "^1.1.4", "through2": "^2.0.0", "tmp": "~0.0.28", "typescript": "~1.8.10", - "uglify-js": "^2.5.0", "yargs": "^6.3.0" }, "devEngines": { diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index e1756d717b165..e5f5328a1b34b 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -2,9 +2,10 @@ const rollup = require('rollup').rollup; const babel = require('rollup-plugin-babel'); +const closure = require('rollup-plugin-closure-compiler-js'); const commonjs = require('rollup-plugin-commonjs'); const alias = require('rollup-plugin-alias'); -const uglify = require('rollup-plugin-uglify'); +const prettier = require('rollup-plugin-prettier'); const replace = require('rollup-plugin-replace'); const chalk = require('chalk'); const join = require('path').join; @@ -24,7 +25,6 @@ const syncReactNativeRT = require('./sync').syncReactNativeRT; const syncReactNativeCS = require('./sync').syncReactNativeCS; const Packaging = require('./packaging'); const Header = require('./header'); -const closure = require('rollup-plugin-closure-compiler-js'); const UMD_DEV = Bundles.bundleTypes.UMD_DEV; const UMD_PROD = Bundles.bundleTypes.UMD_PROD; @@ -51,31 +51,16 @@ const errorCodeOpts = { errorMapFilePath: 'scripts/error-codes/codes.json', }; -function getHeaderSanityCheck(bundleType, globalName) { - switch (bundleType) { - case FB_DEV: - case FB_PROD: - case RN_DEV: - case RN_PROD: - let hasteFinalName = globalName; - switch (bundleType) { - case FB_DEV: - case RN_DEV: - hasteFinalName += '-dev'; - break; - case FB_PROD: - case RN_PROD: - hasteFinalName += '-prod'; - break; - } - return hasteFinalName; - case UMD_DEV: - case UMD_PROD: - return reactVersion; - default: - return null; - } -} +const closureOptions = { + compilationLevel: 'SIMPLE', + languageIn: 'ECMASCRIPT5_STRICT', + languageOut: 'ECMASCRIPT5_STRICT', + env: 'CUSTOM', + warningLevel: 'QUIET', + applyInputSourceMaps: false, + useTypesForOptimization: false, + processCommonJsModules: false, +}; function getBanner(bundleType, globalName, filename, moduleType) { if (moduleType === RECONCILER) { @@ -261,7 +246,6 @@ function getRollupOutputOptions( return Object.assign( {}, { - banner: getBanner(bundleType, globalName, filename, moduleType), destDir: 'build/', file: 'build/' + @@ -270,7 +254,6 @@ function getRollupOutputOptions( filename, globalName ), - footer: getFooter(bundleType, filename, moduleType), format, globals, interop: false, @@ -323,55 +306,6 @@ function getFilename(name, globalName, bundleType) { } } -function getUglifyConfig(configs) { - var mangle = configs.mangle; - var preserveVersionHeader = configs.preserveVersionHeader; - var removeComments = configs.removeComments; - var headerSanityCheck = configs.headerSanityCheck; - return { - warnings: false, - compress: { - screw_ie8: true, - dead_code: true, - unused: true, - drop_debugger: true, - // we have a string literal