Skip to content

Commit 3f969cb

Browse files
tomduncalffacebook-github-bot
authored andcommitted
Add minify flag to react-native bundle command
Summary: We have found that it is useful to work with production rather than dev bundles when working on e.g. performance and animation tuning. For a larger app, `react-native bundle` with `--dev false` can get very slow due to minification - in our case, this was especially true of library code (e.g. the AWS SDK taking nearly 15 secs to minify on a top-spec MBP 15"). This is fine when just building every now and then, but when making frequent changes and rebuilding, it becomes quite painful. Currently there is no way to perform a release (non-dev) build, with minification disabled. This PR adds an optional `--minify` flag to enable developers to disable minification, reducing build times significantly for our use case. Checked output bundle size, to ensure behaviour stays the same as the existing default when `--minify` is not specified, and that the `minify` flag gets passed through to Metro bundler correctly if specified. N/A [GENERAL] [ENHANCEMENT] [Bundler] - Added optional --minify flag to bundler Closes #17702 Differential Revision: D6806356 Pulled By: shergin fbshipit-source-id: c466a2dea692561f8b2002118662c3affc71b991
1 parent 8ffc16c commit 3f969cb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

local-cli/bundle/buildBundle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async function buildBundle(
5454
maxWorkers: number,
5555
resetCache: boolean,
5656
transformer: string,
57+
minify: boolean,
5758
},
5859
config: ConfigT,
5960
output = outputBundle,
@@ -71,7 +72,7 @@ async function buildBundle(
7172
entryFile: args.entryFile,
7273
sourceMapUrl,
7374
dev: args.dev,
74-
minify: !args.dev,
75+
minify: args.minify !== undefined ? args.minify : !args.dev,
7576
platform: args.platform,
7677
};
7778

local-cli/bundle/bundleCommandLineArgs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ module.exports = [
2424
description: 'If false, warnings are disabled and the bundle is minified',
2525
parse: (val) => val === 'false' ? false : true,
2626
default: true,
27+
}, {
28+
command: '--minify [boolean]',
29+
description: 'Allows overriding whether bundle is minified. This defaults to ' +
30+
'false if dev is true, and true if dev is false. Disabling minification ' +
31+
'can be useful for speeding up production builds for testing purposes.',
32+
parse: (val) => val === 'false' ? false : true,
2733
}, {
2834
command: '--bundle-output <string>',
2935
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',

0 commit comments

Comments
 (0)