Skip to content

Instantly share code, notes, and snippets.

@MiguelCastillo
Created November 26, 2016 21:26
Show Gist options
  • Save MiguelCastillo/3edea86f4b1c8303624294fdca134e5a to your computer and use it in GitHub Desktop.
Save MiguelCastillo/3edea86f4b1c8303624294fdca134e5a to your computer and use it in GitHub Desktop.
function livereload(options) {
var lr = require("tiny-lr");
var server = lr();
var port = options || 35729;
server.listen(port, function(err) {
console.log("livereload server started");
});
function bundleVisitor(cb) {
return function getBundleNames(bundle) {
if (bundle) {
cb(bundle);
}
return bundle;
};
}
return {
postbundle: function(bundler, context) {
var bundleDest = [];
context.visitBundles(bundleVisitor(function(bundle) {
bundleDest.push(bundle.dest);
}));
if (bundleDest.length) {
server.changed({
body: {
files: bundleDest
}
});
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment