Skip to content

Commit 1a67dda

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
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: #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
1 parent d435d26 commit 1a67dda

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

react.gradle

+13-4
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,21 @@ afterEvaluate {
159159
def devEnabled = !(config."devDisabledIn${targetName}"
160160
|| targetName.toLowerCase().contains("release"))
161161

162-
def extraArgs = config.extraPackagerArgs ?: [];
162+
def extraArgs = []
163163

164164
if (bundleConfig) {
165-
extraArgs = extraArgs.clone()
166-
extraArgs.add("--config");
167-
extraArgs.add(bundleConfig);
165+
extraArgs.add("--config")
166+
extraArgs.add(bundleConfig)
167+
}
168+
169+
// Hermes doesn't require JS minification.
170+
if (enableHermes && !devEnabled) {
171+
extraArgs.add("--minify")
172+
extraArgs.add("false")
173+
}
174+
175+
if (config.extraPackagerArgs) {
176+
extraArgs.addAll(config.extraPackagerArgs)
168177
}
169178

170179
commandLine(*execCommand, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",

scripts/react-native-xcode.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ if [[ $EMIT_SOURCEMAP == true ]]; then
163163
EXTRA_ARGS="$EXTRA_ARGS --sourcemap-output $PACKAGER_SOURCEMAP_FILE"
164164
fi
165165

166+
# Hermes doesn't require JS minification.
167+
if [[ $USE_HERMES == true && $DEV == false ]]; then
168+
EXTRA_ARGS="$EXTRA_ARGS --minify false"
169+
fi
170+
166171
"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
167172
$CONFIG_ARG \
168173
--entry-file "$ENTRY_FILE" \
@@ -187,7 +192,7 @@ else
187192
if [[ $EMIT_SOURCEMAP == true ]]; then
188193
EXTRA_COMPILER_ARGS="$EXTRA_COMPILER_ARGS -output-source-map"
189194
fi
190-
"$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
195+
"$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
191196
if [[ $EMIT_SOURCEMAP == true ]]; then
192197
HBC_SOURCEMAP_FILE="$BUNDLE_FILE.map"
193198
"$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE"

0 commit comments

Comments
 (0)