Giter Club home page Giter Club logo

node-livereload's Introduction

node-livereload

An implementation of the LiveReload server in Node.js. It's an alternative to the graphical http://livereload.com/ application, which monitors files for changes and reloads your web browser.

Example Usage

First, install the LiveReload browser plugins by visiting http://help.livereload.com/kb/general-use/browser-extensions.

To use livereload from the command line:

$ npm install -g livereload
$ livereload [path]

Or to use the api within a project:

$ npm install livereload

Then, simply create a server and fire it up.

livereload = require('livereload');
server = livereload.createServer();
server.watch(__dirname + "/public");

You can also use this with a Connect server:

connect = require('connect');
connect.createServer(
  connect.compiler({ src: __dirname + "/public", enable: ['less'] }),
  connect.staticProvider(__dirname + "/public")
).listen(3000);

livereload = require('livereload');
server = livereload.createServer({exts: ['less']});
server.watch(__dirname + "/public");

Watching multiple paths:

Passing an array of paths will allow you to watch multiple directories. All directories have the same configuration options.

server.watch([__dirname + "/js", __dirname + "/css"]);

Using originalPath option:

// server.js
var server = livereload.createServer({
    originalPath: "http://domain.com"
});
server.watch('/User/Workspace/test');

$ node server.js

<!-- html -->
<head>
    <link rel="stylesheet" href="http://domain.com/css/style.css">
</head>

When /User/Workspace/test/css/style.css modified, the stylesheet will be reload.

Command-line Options

The commandline options are

  • -p or --port to specify the listening port
  • -i or --interval to specify the listening interval in milliseconds. Default is 1000.

Specify the path when using the options.

$ livereload . -i 200

API Options

The createServer() method supports a few basic options, passed as a JavaScript object:

  • https is an optional object of options to be passed to https.createServer (if not provided, http.createServer is used instead)
  • port is the listening port. It defaults to 35729 which is what the LiveReload extensions use currently.
  • exts is an array of extensions you want to observe. The default extensions are html, css, js, png, gif, jpg, php, php5, py, rb, erb, and "coffee."
  • applyJSLive tells LiveReload to reload JavaScript files in the background instead of reloading the page. The default for this is false.
  • applyCSSLive tells LiveReload to reload CSS files in the background instead of refreshing the page. The default for this is true.
  • exclusions lets you specify files to ignore. By default, this includes .git/, .svn/, and .hg/
  • originalPath Set URL you use for development, e.g 'http:/domain.com', then LiveReload will proxy this url to local path.
  • overrideURL override the stylesheet href with your set.

Limitations

Right now this is extremely simple. It relies on polling so there's a delay in refreshing the browser. It could be faster.

License

Copyright (c) 2010-2014 Brian P. Hogan and Joshua Peek

Released under the MIT license. See LICENSE for details.

node-livereload's People

Contributors

eugeneware avatar hugojosefson avatar ismaail avatar jaymorrow avatar josh avatar leftium avatar napcs avatar nemodreamer avatar nv avatar offirmo avatar oklai avatar timhuff avatar tiye avatar wavded avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.