Skip to content

Instantly share code, notes, and snippets.

@maheshsenni
Last active May 10, 2016 00:40
Show Gist options
  • Save maheshsenni/7fa7eeab61b390b0958f287ac72ed332 to your computer and use it in GitHub Desktop.
Save maheshsenni/7fa7eeab61b390b0958f287ac72ed332 to your computer and use it in GitHub Desktop.
Step 2b - Creating a module bundler with Hot Module Replacement
/* This file is included in the page running the app */
(function() {
// create an instance of Socket.IO for listening
// to websocket messages
var socket = io();
// listen for 'file-change' message
socket.on('file-change', function(msg) {
console.log('File changed: ' + msg.id);
// reload the browser to get the latest changes
// we will replace this later to "hot update"
// only the changed modules
window.location.reload();
});
})();
<!DOCTYPE html>
<html>
<head>
<title>HMR sample</title>
</head>
<body>
<h2>Counter</h2>
<h2 id="counter"></h2>
<!-- Provided by Socket.IO for listening to websocket messages -->
<script src="/socket.io/socket.io.js"></script>
<!-- Code which performs some action after a websocket message is received -->
<script src="hmr.js"></script>
<!-- Counter application code -->
<script src="bundle.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment