From 1a67dda668c71d961a4bb3b0cdf6aa22c0e5c138 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Tue, 1 Dec 2020 17:15:07 -0800 Subject: [PATCH] Don't minify JS bundle by default when using hermes (#30496) Summary: Minification is not needed for hermes as it does all required optimisations on the bytecode. This is what facebook does internally for hermes bundles and I also validated by comparing the bytecode bundle size on a minified and non-minified bundle. ## Changelog [General] [Changed] - Don't minify JS bundle by default when using hermes Pull Request resolved: https://github.com/facebook/react-native/pull/30496 Test Plan: Verified that the JS bundled generated on Android and iOS when using hermes is not minified by checking the generated JS file manually. Reviewed By: rickhanlonii Differential Revision: D25235195 Pulled By: cpojer fbshipit-source-id: ad2131aab4dfd17ab53b6a5720ed0e2f1b09cca4 --- react.gradle | 17 +++++++++++++---- scripts/react-native-xcode.sh | 7 ++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/react.gradle b/react.gradle index 5a3bf6ba9cb982..04b94aad9ee513 100644 --- a/react.gradle +++ b/react.gradle @@ -159,12 +159,21 @@ afterEvaluate { def devEnabled = !(config."devDisabledIn${targetName}" || targetName.toLowerCase().contains("release")) - def extraArgs = config.extraPackagerArgs ?: []; + def extraArgs = [] if (bundleConfig) { - extraArgs = extraArgs.clone() - extraArgs.add("--config"); - extraArgs.add(bundleConfig); + extraArgs.add("--config") + extraArgs.add(bundleConfig) + } + + // Hermes doesn't require JS minification. + if (enableHermes && !devEnabled) { + extraArgs.add("--minify") + extraArgs.add("false") + } + + if (config.extraPackagerArgs) { + extraArgs.addAll(config.extraPackagerArgs) } commandLine(*execCommand, bundleCommand, "--platform", "android", "--dev", "${devEnabled}", diff --git a/scripts/react-native-xcode.sh b/scripts/react-native-xcode.sh index 9b059a6597d776..228a5ec885e5cc 100755 --- a/scripts/react-native-xcode.sh +++ b/scripts/react-native-xcode.sh @@ -163,6 +163,11 @@ if [[ $EMIT_SOURCEMAP == true ]]; then EXTRA_ARGS="$EXTRA_ARGS --sourcemap-output $PACKAGER_SOURCEMAP_FILE" fi +# Hermes doesn't require JS minification. +if [[ $USE_HERMES == true && $DEV == false ]]; then + EXTRA_ARGS="$EXTRA_ARGS --minify false" +fi + "$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \ $CONFIG_ARG \ --entry-file "$ENTRY_FILE" \ @@ -187,7 +192,7 @@ else if [[ $EMIT_SOURCEMAP == true ]]; then EXTRA_COMPILER_ARGS="$EXTRA_COMPILER_ARGS -output-source-map" fi - "$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE" + "$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE" if [[ $EMIT_SOURCEMAP == true ]]; then HBC_SOURCEMAP_FILE="$BUNDLE_FILE.map" "$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE"