mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
Make HMR faster
Summary: public At the moment, when the user changes a file we end up pulling the dependencies of the entry point to build the bundle. This could take a long time if the bundle is big. To avoid it, lets introduce a new parameter to `getDependencies` to be able to avoid processing the modules recursively and reuse the resolution responseto build the bundle. Reviewed By: davidaurelio Differential Revision: D2862850 fb-gh-sync-id: b8ae2b811a8ae9aec5612f9655d1c762671ce730
This commit is contained in:
committed by
facebook-github-bot-9
parent
c8a0a3eff6
commit
65b8ff17f3
@@ -74,6 +74,7 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||
dependenciesCache,
|
||||
dependenciesModulesCache,
|
||||
shallowDependencies,
|
||||
resolutionResponse: response,
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -123,7 +124,23 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||
// to the client may have changed
|
||||
const oldDependencies = client.shallowDependencies[filename];
|
||||
if (arrayEquals(deps, oldDependencies)) {
|
||||
return [packagerServer.getModuleForPath(filename)];
|
||||
// Need to create a resolution response to pass to the bundler
|
||||
// to process requires after transform. By providing a
|
||||
// specific response we can compute a non recursive one which
|
||||
// is the least we need and improve performance.
|
||||
return packagerServer.getDependencies({
|
||||
platform: client.platform,
|
||||
dev: true,
|
||||
entryFile: filename,
|
||||
recursive: true,
|
||||
}).then(response => {
|
||||
const module = packagerServer.getModuleForPath(filename);
|
||||
|
||||
return {
|
||||
modulesToUpdate: [module],
|
||||
resolutionResponse: response,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// if there're new dependencies compare the full list of
|
||||
@@ -133,9 +150,10 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||
dependenciesCache,
|
||||
dependenciesModulesCache,
|
||||
shallowDependencies,
|
||||
resolutionResponse,
|
||||
}) => {
|
||||
if (!client) {
|
||||
return [];
|
||||
return {};
|
||||
}
|
||||
|
||||
// build list of modules for which we'll send HMR updates
|
||||
@@ -151,10 +169,13 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||
client.dependenciesModulesCache = dependenciesModulesCache;
|
||||
client.shallowDependencies = shallowDependencies;
|
||||
|
||||
return modulesToUpdate;
|
||||
return {
|
||||
modulesToUpdate,
|
||||
resolutionResponse,
|
||||
};
|
||||
});
|
||||
})
|
||||
.then(modulesToUpdate => {
|
||||
.then(({modulesToUpdate, resolutionResponse}) => {
|
||||
if (!client) {
|
||||
return;
|
||||
}
|
||||
@@ -168,6 +189,7 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||
entryFile: client.bundleEntry,
|
||||
platform: client.platform,
|
||||
modules: modulesToUpdate,
|
||||
resolutionResponse,
|
||||
})
|
||||
})
|
||||
.then(bundle => {
|
||||
|
||||
Reference in New Issue
Block a user