Skip to content

Instantly share code, notes, and snippets.

@maheshsenni
Last active May 14, 2016 16:23
Show Gist options
  • Save maheshsenni/553477d9fbed2e8be1070c8d8935e270 to your computer and use it in GitHub Desktop.
Save maheshsenni/553477d9fbed2e8be1070c8d8935e270 to your computer and use it in GitHub Desktop.
Step 3 - Creating a module bundler with Hot Module Replacement
// response with a JSONP callback function which does hot module replacement
app.get('/hot-update', function(req, res){
var moduleId = req.query.id;
// wrap the module code around JSONP callback function
var hotUpdateScriptTxt = 'hotUpdate({ "' + moduleId + '":[function(require,module,exports){';
// find the updated module in moduleDepsJSON (output from module-deps)
var updatedModule = moduleDepsJSON.filter(function(dep) {
return dep.id === moduleId;
})[0];
// append source of the updated module to the hot update script
hotUpdateScriptTxt += updatedModule.source;
// finish up hotUpdateScriptTxt
hotUpdateScriptTxt += '},';
// append dependencies
hotUpdateScriptTxt += JSON.stringify(updatedModule.deps);
hotUpdateScriptTxt += ']});';
// send the update script
res.send(hotUpdateScriptTxt);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment