Skip to content

Commit

Permalink
Make webpackHotDevClient support webpack 2 too (facebook#840)
Browse files Browse the repository at this point in the history
* Support webpack 2

* Code style
  • Loading branch information
michalkvasnicak authored and feiqitian committed Oct 25, 2016
1 parent 91c0731 commit b24a89a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/react-dev-utils/webpackHotDevClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ function tryApplyUpdates(onHotUpdateSuccess) {
return;
}

// https://webpack.github.io/docs/hot-module-replacement.html#check
module.hot.check(/* autoApply */true, function(err, updatedModules) {
function handleApplyUpdates(err, updatedModules) {
if (err || !updatedModules) {
window.location.reload();
return;
Expand All @@ -288,5 +287,20 @@ function tryApplyUpdates(onHotUpdateSuccess) {
// While we were updating, there was a new update! Do it again.
tryApplyUpdates();
}
});
}

// https://webpack.github.io/docs/hot-module-replacement.html#check
var result = module.hot.check(/* autoApply */true, handleApplyUpdates);

// // Webpack 2 returns a Promise instead of invoking a callback
if (result && result.then) {
result.then(
function(updatedModules) {
handleApplyUpdates(null, updatedModules);
},
function(err) {
handleApplyUpdates(err, null);
}
);
}
};

0 comments on commit b24a89a

Please sign in to comment.