Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Add JS Minify option to settings in Android
Browse files Browse the repository at this point in the history
Summary: Useful for debugging minification issues and more representative perf testing.

Differential Revision: D3080489

fb-gh-sync-id: 315f696d3847a213eb95f247f409173a01864567
shipit-source-id: 315f696d3847a213eb95f247f409173a01864567
  • Loading branch information
sahrens authored and Facebook Github Bot 0 committed Mar 22, 2016
1 parent e3fe66a commit 1f94a00
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public boolean isJSDevModeEnabled() {
return true;
}

@Override
public boolean isJSMinifyEnabled() {
return false;
}

@Override
public boolean isElementInspectorEnabled() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -66,14 +67,20 @@ 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);
}

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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public interface DeveloperSettings {
*/
boolean isJSDevModeEnabled();

/**
* @return Whether JS bundle should be minified.
*/
boolean isJSMinifyEnabled();

/**
* @return Whether element inspector is enabled.
*/
Expand Down
6 changes: 6 additions & 0 deletions ReactAndroid/src/main/res/devsupport/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
android:summary="Load JavaScript bundle with __DEV__ = true for easier debugging. Disable for performance testing."
android:defaultValue="true"
/>
<CheckBoxPreference
android:key="js_minify_debug"
android:title="JS Minify"
android:summary="Load JavaScript bundle with minify=true for debugging minification issues."
android:defaultValue="false"
/>
<CheckBoxPreference
android:key="animations_debug"
android:title="Animations FPS Summaries"
Expand Down

0 comments on commit 1f94a00

Please sign in to comment.