Created
May 10, 2016 00:24
-
-
Save maheshsenni/de95887e044f870cc93b365be415697b to your computer and use it in GitHub Desktop.
Step 2 - 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
// 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