Improve HMR performance by allowing to specify bundlingOptions to getShallowDependencies() method

Reviewed By: jeanlauliac

Differential Revision: D5745205

fbshipit-source-id: a69ac40bb676a809e3786681179e2b4bac392ce6
This commit is contained in:
Rafael Oleza 2017-09-01 08:44:50 -07:00 committed by Facebook Github Bot
parent 8907de28ac
commit 717a8c7f61
2 changed files with 30 additions and 14 deletions

View File

@ -564,7 +564,7 @@ class Bundler {
});
}
getShallowDependencies({
async getShallowDependencies({
entryFile,
rootEntryFile,
platform,
@ -572,6 +572,7 @@ class Bundler {
minify = !dev,
hot = false,
generateSourceMaps = false,
bundlingOptions,
}: {
entryFile: string,
+rootEntryFile: string,
@ -580,8 +581,10 @@ class Bundler {
minify?: boolean,
hot?: boolean,
generateSourceMaps?: boolean,
bundlingOptions?: BundlingOptions,
}): Promise<Array<string>> {
return this.getTransformOptions(rootEntryFile, {
if (!bundlingOptions) {
bundlingOptions = await this.getTransformOptions(rootEntryFile, {
enableBabelRCLookup: this._opts.enableBabelRCLookup,
dev,
generateSourceMaps,
@ -589,10 +592,13 @@ class Bundler {
minify,
platform,
projectRoots: this._projectRoots,
}).then(bundlingOptions =>
this._resolverPromise.then(resolver =>
resolver.getShallowDependencies(entryFile, bundlingOptions.transformer),
),
});
}
const notNullOptions = bundlingOptions;
return this._resolverPromise.then(resolver =>
resolver.getShallowDependencies(entryFile, notNullOptions.transformer),
);
}

View File

@ -33,6 +33,7 @@ const {
import type Module, {HasteImpl} from '../node-haste/Module';
import type {IncomingMessage, ServerResponse} from 'http';
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type {BundlingOptions} from '../Bundler';
import type Bundle from '../Bundler/Bundle';
import type HMRBundle from '../Bundler/HMRBundle';
import type {Reporter} from '../lib/reporting';
@ -124,6 +125,7 @@ type DependencyOptions = {|
+platform: ?string,
+recursive: boolean,
+rootEntryFile: string,
+bundlingOptions?: BundlingOptions,
|};
type BuildInfo = {|
@ -342,7 +344,14 @@ class Server {
options.platform != null
? options.platform
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
const {entryFile, dev, minify, hot, rootEntryFile} = options;
const {
entryFile,
dev,
minify,
hot,
rootEntryFile,
bundlingOptions,
} = options;
return this._bundler.getShallowDependencies({
entryFile,
rootEntryFile,
@ -351,6 +360,7 @@ class Server {
minify,
hot,
generateSourceMaps: false,
bundlingOptions,
});
});
}