Livestyle is a small web server that refreshes the stylesheets on your web sites live as you edit them.
The server then notifies the client to reload specific stylesheets when they are updated on the file system.
The livestyle client also falls back to active polling, which means you can use the client as a standalone script on your normal web server.
Use livestyle to get live feedback while staying in your favorite editor. Effective use cases spotted so far:
If you are looking for a grunt task doing the same, take a look at grunt-livestyle.
Livestyle installs an executable script on your system called
To get started quickly just change the directory to where your
document root is and run the
livestyle command. The server will now
listen on port 3000.
Here's the full set of command line options:
The directory to serve static files from. Unless
specified, it defaults to the current working directory. If you want
to serve static files in
--root must be specified
The local hostname or IP-address to listen on. Defaults to
The local post number to listen on. Defaults to
Instructs livestyle to proxy requests for everything but CSS files to
a remote server, as determined by the
Accept request header.
Translate the paths of incoming requests. Think of it as a very
primitive mod_rewrite that only works on request path prefixes. For
example, to translate all requests for
/bar/*, use this
Multiple --map switches are allowed. When used in conjunction with
--proxy, the mappings are applied before proxying the request.
Compile less assets on-the-fly using express-compiless. Also supports watching @import'ed less assets.
Compile sass assets on-the-fly using express-compile-sass. Also supports watching @import'ed sass assets.
add missing css vendor prefixes on the fly using express-autoprefixer
If you only provide the flag with no value (like this:
--autoprefixer) it will use the autoprefixer defaults. '> 1%, last
2 versions, Firefox ESR, Opera 12.1'.
You can pass options as a string of supported browsers separated by comma. For syntax and valid options see the autoprefixer projectpage.
If you wish to support IE9 and the last 2 versions of every browser
you should provide the options like this:
--autoprefixer "ie > 8, last 2 versions".
Process images on the server according to the query string using using express-processimage.
Also watch the HTML file itself and refresh if it changes on disc.
Also watch (background) images used by CSS and refresh them if they change on disc.
Outputs a bunch of debugging information on both the server and the client.
If set, will use fs.watchFile instead of fs.watch. If you experience problems that the server stops watching a file after the first time you save a file, this method will help.
Only notify clients about a changed file if its
increased. Experimental, only supported when using
Livestyle requires NodeJS and npm to be installed. See this page for installation instructions: https://github.com/joyent/node/wiki/Installation
When the prerequisites are in place, run the following command:
npm install -g livestyle
And you are done.
Currently there are some troubles with updating stylesheets using @import in IE, which you want to avoid anyway http://www.stevesouders.com/blog/2009/04/09/dont-use-import/
Livestyle supports asynchronous loading and injection of stylesheets. If you are using requirejs you might want to take a look at css.js and less.js, wich can be used as module loaders for both less and css files using requirejs like so:
These two loaders are both usable without livestyle.
The less.js loader will change behavior depending on wether you have
--compiless flag for livestyle to make live updates possible.
You are hitting the limit of inotify watchers on your system. To remedy this, you can increase the limit. On modern computers it should not be worsening the performance significantly.
To check what your current limit is run:
$ cat /proc/sys/fs/inotify/max_user_watches
It should generally be safe to just double that if you see this error.
$ echo 16384 > /proc/sys/fs/inotify/max_user_watches
You will need to run the above command with super user privileges.
To make the change permanent you can add the following line to the /etc/sysctl.conf file.
This solution is assuming you are running Debian.
Since livestyle watches the css files that are actually served to the browser, livestyle work with any CSS preprocessor that runs on the server out of the box.
If you want live updates you will of course need to enable your preprocessor's option to automatically build a new CSS files for each file update. livestyle will then detect the update in the built file and push it to the client.
There are two CSS preprocessors that run in the browser, which is a bit of a special case:
Prefixfree inserts vendor prefixes for the style properties that need them. It does this runtime in the browser by fetching the stylesheet content through XHR and replace the link tags with a style block with prefixed CSS. Livestyle now supports prefixfree.
Less.js injects preprocessed style into the page by loading .less files and reworking the content to real CSS. Livestyle supports live updates using Less.js by refreshing all less stylesheets on the page.
LiveStyle is licensed under a standard 3-clause BSD license -- see the
LICENSE-file for details.