Add JS Minify option to settings in Android

Summary: Useful for debugging minification issues and more representative perf testing.

Differential Revision: D3080489

fb-gh-sync-id: 315f696d3847a213eb95f247f409173a01864567
shipit-source-id: 315f696d3847a213eb95f247f409173a01864567
This commit is contained in:
Spencer Ahrens
2016-03-21 21:11:01 -07:00
committed by Facebook Github Bot 0
parent e3fe66acfc
commit 1f94a00785
5 changed files with 38 additions and 8 deletions

View File

@@ -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 class DevInternalSettings implements
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 class DevInternalSettings implements
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();
}
}

View File

@@ -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 @@ public class DevServerHelper {
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 @@ public class DevServerHelper {
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 class DevServerHelper {
}
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());
}
}

View File

@@ -29,6 +29,11 @@ public interface DeveloperSettings {
*/
boolean isJSDevModeEnabled();
/**
* @return Whether JS bundle should be minified.
*/
boolean isJSMinifyEnabled();
/**
* @return Whether element inspector is enabled.
*/