diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java index 417638dd2a8f8c..6d0946d8dd5a81 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactSettingsForTests.java @@ -27,6 +27,11 @@ public boolean isJSDevModeEnabled() { return true; } + @Override + public boolean isJSMinifyEnabled() { + return false; + } + @Override public boolean isElementInspectorEnabled() { return false; diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java index 825bc1c598435c..349cd22dbbefe0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevInternalSettings.java @@ -30,6 +30,7 @@ public class DevInternalSettings implements private static final String PREFS_FPS_DEBUG_KEY = "fps_debug"; private static final String PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug"; + private static final String PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug"; private static final String PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host"; private static final String PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug"; private static final String PREFS_RELOAD_ON_JS_CHANGE_KEY = "reload_on_js_change"; @@ -66,6 +67,11 @@ public boolean isJSDevModeEnabled() { return mPreferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true); } + @Override + public boolean isJSMinifyEnabled() { + return mPreferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false); + } + public @Nullable String getDebugServerHost() { return mPreferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null); } @@ -73,7 +79,8 @@ public boolean isJSDevModeEnabled() { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (PREFS_FPS_DEBUG_KEY.equals(key) || PREFS_RELOAD_ON_JS_CHANGE_KEY.equals(key) || - PREFS_JS_DEV_MODE_DEBUG_KEY.equals(key)) { + PREFS_JS_DEV_MODE_DEBUG_KEY.equals(key) || + PREFS_JS_MINIFY_DEBUG_KEY.equals(key)) { mDebugManager.reloadSettings(); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index 78b570e6f3c614..e99c7a9b058296 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -56,7 +56,7 @@ public class DevServerHelper { private static final String DEVICE_LOCALHOST = "localhost:8081"; private static final String BUNDLE_URL_FORMAT = - "http://%s/%s.bundle?platform=android&dev=%s&hot=%s"; + "http://%s/%s.bundle?platform=android&dev=%s&hot=%s&minify=%s"; private static final String SOURCE_MAP_URL_FORMAT = BUNDLE_URL_FORMAT.replaceFirst("\\.bundle", ".map"); private static final String LAUNCH_CHROME_DEVTOOLS_COMMAND_URL_FORMAT = @@ -128,6 +128,13 @@ private boolean getDevMode() { return mSettings.isJSDevModeEnabled(); } + /** + * @return whether we should request minified JS bundles. + */ + private boolean getJSMinifyMode() { + return mSettings.isJSMinifyEnabled(); + } + /** * @return whether we should enabled HMR when requesting JS bundles. */ @@ -169,15 +176,15 @@ private boolean isRunningOnStockEmulator() { return Build.FINGERPRINT.contains("generic"); } - private static String createBundleURL(String host, String jsModulePath, boolean devMode, boolean hmr) { - return String.format(Locale.US, BUNDLE_URL_FORMAT, host, jsModulePath, devMode, hmr); + private static String createBundleURL(String host, String jsModulePath, boolean devMode, boolean hmr, boolean jsMinify) { + return String.format(Locale.US, BUNDLE_URL_FORMAT, host, jsModulePath, devMode, hmr, jsMinify); } public void downloadBundleFromURL( final BundleDownloadCallback callback, final String jsModulePath, final File outputFile) { - final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath, getDevMode(), getHMR()); + final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath, getDevMode(), getHMR(), getJSMinifyMode()); final Request request = new Request.Builder() .url(bundleURL) .build(); @@ -397,17 +404,17 @@ public void onResponse(Response response) throws IOException { } public String getSourceMapUrl(String mainModuleName) { - return String.format(Locale.US, SOURCE_MAP_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode(), getHMR()); + return String.format(Locale.US, SOURCE_MAP_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode(), getHMR(), getJSMinifyMode()); } public String getSourceUrl(String mainModuleName) { - return String.format(Locale.US, BUNDLE_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode(), getHMR()); + return String.format(Locale.US, BUNDLE_URL_FORMAT, getDebugServerHost(), mainModuleName, getDevMode(), getHMR(), getJSMinifyMode()); } public String getJSBundleURLForRemoteDebugging(String mainModuleName) { // The host IP we use when connecting to the JS bundle server from the emulator is not the // same as the one needed to connect to the same server from the Chrome proxy running on the // host itself. - return createBundleURL(getHostForJSProxy(), mainModuleName, getDevMode(), getHMR()); + return createBundleURL(getHostForJSProxy(), mainModuleName, getDevMode(), getHMR(), getJSMinifyMode()); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java index 5ff8dfbf76f98a..5defb93865d605 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/debug/DeveloperSettings.java @@ -29,6 +29,11 @@ public interface DeveloperSettings { */ boolean isJSDevModeEnabled(); + /** + * @return Whether JS bundle should be minified. + */ + boolean isJSMinifyEnabled(); + /** * @return Whether element inspector is enabled. */ diff --git a/ReactAndroid/src/main/res/devsupport/xml/preferences.xml b/ReactAndroid/src/main/res/devsupport/xml/preferences.xml index 99f5408c050871..b41f9c50a5cf3f 100644 --- a/ReactAndroid/src/main/res/devsupport/xml/preferences.xml +++ b/ReactAndroid/src/main/res/devsupport/xml/preferences.xml @@ -13,6 +13,12 @@ android:summary="Load JavaScript bundle with __DEV__ = true for easier debugging. Disable for performance testing." android:defaultValue="true" /> +