gulp-livereload = function (opts) { options = _assign(options, opts); var glr = es.map(function(file, done) { var filePath = file.path; exports.changed(filePath); done(null, file); }); if (options.start) exports.listen(options); return glr; }
n/a
changed = function (filePath) { if (!exports.server) { debug('no server listening, nothing notified.'); return; } if (typeof filePath === 'object') { filePath = filePath.path; } if (options.basePath) { filePath = '/' + relative(options.basePath, filePath); } exports.server.changed({ body: { files: [ filePath ] } }); if (!options.quiet) { gutil.log(magenta(filePath) + ' reloaded.'); } }
...
*/
module.exports = exports = function(opts) {
options = _assign(options, opts);
var glr = es.map(function(file, done) {
var filePath = file.path;
exports.changed(filePath);
done(null, file);
});
if (options.start) exports.listen(options);
return glr;
};
...
listen = function (opts, cb) { if (exports.server) return; if (typeof opts === 'number') { opts = { port: opts }; } else if (typeof opts === 'function') { cb = opts; opts = {}; } options = _assign(options, opts); exports.server = new minilr.Server(options); exports.server.listen(options.port, options.host, function() { debug('now listening on port %d', options.port); if(typeof cb === 'function') cb.apply(exports.server, arguments); }); }
...
var glr = es.map(function(file, done) {
var filePath = file.path;
exports.changed(filePath);
done(null, file);
});
if (options.start) exports.listen(options);
return glr;
};
// Note: This is a good way to directly set the settings once throughout
// the program, a reference to the global options
exports.options = options;
...
function middleware(opts) { var srv = new Server(opts); servers.push(srv); return function minilr(req, res, next) { srv.handler(req, res, next); }; }
n/a
reload = function (filePath) { exports.changed(filePath || options.reloadPage); }
...
### livereload.changed(path)
Alternatively, you can call this function to send changes to the livereload server. You should provide either a simple string or
an object, if an object is given it expects the object to have a `path` property.
> NOTE: Calling this function without providing a `path` will do nothing.
### livereload.reload([file])
You can also tell the browser to refresh the entire page. This assumes the page is called `index.html`, you can change it by providing
an **optional** `file` path or change it globally with the options `reloadPage`.
### livereload.middleware
You can also directly access the middleware of the underlying server instance (mini-lr.middleware) for hookup through express, connect
, or some other middleware app
...