Skip to content

Instantly share code, notes, and snippets.

@maheshsenni
Created May 10, 2016 00:24
Show Gist options
  • Save maheshsenni/de95887e044f870cc93b365be415697b to your computer and use it in GitHub Desktop.
Save maheshsenni/de95887e044f870cc93b365be415697b to your computer and use it in GitHub Desktop.
Step 2 - Creating a module bundler with Hot Module Replacement
// some code here
// websocket connection for notifying browser
var io = require('socket.io')(http);
// some code here
var processFiles = function(callback) {
// some code here
md.pipe(JSONStream.stringify())
// some code here
.on('end', function() {
fs.writeFile('dist/bundle.js', bundleStr, 'utf8', function() {
console.log('Bundle file written...');
if (typeof callback === 'function') {
callback();
}
});
});
md.end({ file: path.join(__dirname, args[0]) });
};
// watch app folder for changes
fs.watch('app', function(event, fileName) {
// create bundle with new changes
processFiles(function() {
// notify the browser of the change
io.emit('file-change', { id: path.join('app', fileName) });
});
});
// some code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment