Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active April 4, 2016 10:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/2aa5b45ed1f230635a04 to your computer and use it in GitHub Desktop.
Save mattdesl/2aa5b45ed1f230635a04 to your computer and use it in GitHub Desktop.
HMR and CSS injection workflow

budo + LiveReactLoad integration

  • stubs out index.html
  • runs watchify
  • serves on port 9966
  • notifies LiveReactLoad on bundle update
  • reloads HTML with LiveReload
  • injects CSS with LiveReload
  • pretty-prints requests to console

Setup:

npm install budo babelify livereactload garnish --save-dev

package.json

"scripts": {
  "start": "node dev | garnish"
}

Run:

npm start

Then open localhost:9966.

#!/usr/bin/env node
var lrload = require('livereactload')
var app = require('budo')('index.js:bundle.js', {
stream: process.stdout,
transform: ['babelify', 'livereactload'],
})
.watch() //watch for *.html, *.css
.live() //start LiveReload server for CSS/HTML
.on('connect', function() {
lrload.listen() //listen for HMR
})
.on('update', function() {
lrload.notify() //trigger HMR
})
.on('watch', function(ev, file) {
app.reload(file) //trigger CSS injection / HTML reload
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment