From 8799b32d58a531442108d4ceb5ed0d87077bbba1 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 8 Nov 2017 00:47:30 +0000 Subject: [PATCH 1/3] Consolidate build process with GCC --- package.json | 4 +- scripts/rollup/build.js | 276 +++++++++++++--------------------------- yarn.lock | 75 +++++++---- 3 files changed, 143 insertions(+), 212 deletions(-) diff --git a/package.json b/package.json index 4b42bb5ebdf26..6ad64860566cd 100644 --- a/package.json +++ b/package.json @@ -83,13 +83,13 @@ "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", + "rollup-plugin-strip-banner": "^0.2.0", "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..47bcbaaa0226c 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -2,10 +2,12 @@ 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 stripBanner = require('rollup-plugin-strip-banner'); const chalk = require('chalk'); const join = require('path').join; const resolve = require('path').resolve; @@ -24,7 +26,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 +52,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 +247,6 @@ function getRollupOutputOptions( return Object.assign( {}, { - banner: getBanner(bundleType, globalName, filename, moduleType), destDir: 'build/', file: 'build/' + @@ -270,7 +255,6 @@ function getRollupOutputOptions( filename, globalName ), - footer: getFooter(bundleType, filename, moduleType), format, globals, interop: false, @@ -280,13 +264,6 @@ function getRollupOutputOptions( ); } -function stripEnvVariables(production) { - return { - __DEV__: production ? 'false' : 'true', - 'process.env.NODE_ENV': production ? "'production'" : "'development'", - }; -} - function getFormat(bundleType) { switch (bundleType) { case UMD_DEV: @@ -323,86 +300,21 @@ 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