Skip to content

Commit

Permalink
Add minify flag to react-native bundle command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tomduncalf authored and facebook-github-bot committed Jan 30, 2018
1 parent 8ffc16c commit 3f969cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion local-cli/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function buildBundle(
maxWorkers: number,
resetCache: boolean,
transformer: string,
minify: boolean,
},
config: ConfigT,
output = outputBundle,
Expand All @@ -71,7 +72,7 @@ async function buildBundle(
entryFile: args.entryFile,
sourceMapUrl,
dev: args.dev,
minify: !args.dev,
minify: args.minify !== undefined ? args.minify : !args.dev,
platform: args.platform,
};

Expand Down
6 changes: 6 additions & 0 deletions local-cli/bundle/bundleCommandLineArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ module.exports = [
description: 'If false, warnings are disabled and the bundle is minified',
parse: (val) => val === 'false' ? false : true,
default: true,
}, {
command: '--minify [boolean]',
description: 'Allows overriding whether bundle is minified. This defaults to ' +
'false if dev is true, and true if dev is false. Disabling minification ' +
'can be useful for speeding up production builds for testing purposes.',
parse: (val) => val === 'false' ? false : true,
}, {
command: '--bundle-output <string>',
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
Expand Down

0 comments on commit 3f969cb

Please sign in to comment.