Last active
May 14, 2016 16:23
-
-
Save maheshsenni/553477d9fbed2e8be1070c8d8935e270 to your computer and use it in GitHub Desktop.
Step 3 - Creating a module bundler with Hot Module Replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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