This is a fork of tiny-lr. The maintainer of tiny-lr appears to be on a hiatus and this fork takes care of lingering issues until the maintainer of tiny-lr (hopefully) returns.
Changes made:
Quieter, removes console.logs
Use WSS when livereload.js is on HTTPS
Normalize windows paths in livereload.js
tiny-lr
This script manages a tiny LiveReload server
implementation you can spawn in the background.
Grunt tasks to start the server and trigger reload notification. Every task
name is prefixed by tinylr-.
Generic targets to include in
your Makefile (include node_modules/tiny-lr/tasks/tiny-lr.mk)
It doesn't have any watch ability, it must be done at the build process or
application level.
Instead, it exposes a very simple API to notify the server that some
changes have been made, that is then broadcasted to every livereload client
connected.
# notify a single changecurl http://localhost:35729/changed?files=style.css# notify using a longer pathcurl http://localhost:35729/changed?files=js/app.js# notify multiple changes, comma or space delimitedcurl http://localhost:35729/changed?files=index.html,style.css,docs/docco.css
Or you can bulk the information into a POST request, with body as a JSON array of files.
curl -X POST http://localhost:35729/changed -d '{ "files": ["style.css", "app.js"] }'
This package exposes a bin you can decide to install globally, but it's not recommended.
tiny-lr --helpUsage: tiny-lr [options]Options: -h, --help - Show help usage -v, --version - Show package version -p, --port - Port to listen on (default: 35729) --pid - Path to the generated PID file (default: ./tiny-lr.pid)
The best way to integrate the runner in your workflow is to add it as a reload
step within your build tool. This build tool can then use the internal binary
linked by npm in node_modules/.bin/tiny-lr to not rely on global installs (or
use the server programmtically).
You can start the server using the binary provided, or use your own start script.
var tinylr = require('tiny-lr');// standard LiveReload portvar port = 35729;// tinylr(opts) => new tinylr.Server(opts);tinylr().listen(port, function() { if(err) { // deal with err return; } console.log('... Listening on %s (pid: %s) ...', port);})
You can define your own route and listen for specific request:
var server = tinylr();server.on('GET /myplace', function(req, res) { res.write('Mine'); res.end();})
And stop the server manually:
server.close();
This will close any websocket connection established and emit a close event.
Middleware
To use as a connect / express middleware, tiny-lr needs query /
bodyParse middlewares prior in the stack.
Any handled requests ends at the tinylr level, not found and errors are
nexted to the rest of the stack.
// This binds both express app and tinylr on the same portvar app = express();app.use(express.query()) .use(express.bodyParser()) .use(tinylr.middleware({ app: app })) .use(express.static(path.resolve('./'))) .use(express.directory(path.resolve('./'))) .listen(35729, function() { console.log('Listening on %d', 35729); })
The port you listen on is important, and tinylr should always listen on
the LiveReload standard one: 35729. Otherwise, you won't be able to rely
on the browser extensions, though you can still use the manual snippet
approach.
You can also start two different servers, one on your app port, the
other listening on the LiveReload port. Check the
examples/express/server.js file to see how.
Using grunt
This package exposes a tasks/ directory, that you can use within your Gruntfile with:
grunt.loadNpmTasks('tiny-lr');
tinylr-start - Starts a new tiny-lr Server, with the provided port.
tinylr-reload - Sends a reload notification to the previously started server.
tinylr-start should be used with the watch task, probably with an alias
that triggers both tinylr-start watch tasks.
tinylr-reload should be configured as a "watch" task in your Gruntfile.