Skip to content

Instantly share code, notes, and snippets.

@maheshsenni
Last active May 14, 2016 16:26
Show Gist options
  • Save maheshsenni/5d8b7a6cd5dbb15512cea00f0ad02e78 to your computer and use it in GitHub Desktop.
Save maheshsenni/5d8b7a6cd5dbb15512cea00f0ad02e78 to your computer and use it in GitHub Desktop.
Step 3a - Creating a module bundler with Hot Module Replacement
// this function will be added to the final bundle produced by
// browser-pack using 'prelude' option
this.hotUpdate = function(updatedModules) {
for (var id in updatedModules) {
if(Object.prototype.hasOwnProperty.call(updatedModules, id)) {
// clear module definition from cache
delete cache[id];
// replace existing module definition from module map
modules[id] = updatedModules[id];
// Update module - 'newRequire' is from browser-pack
newRequire(id);
console.log('Update applied.');
// call entry point modules to bootstrap
for(var i=0;i<entry.length;i++) {
// delete existing entry point module in cache
// so that it is reinitialized
delete cache[entry[i]];
// call entry point module which will run
// with new updates in cache
newRequire(entry[i]);
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment