← 全部工具

live-server

热度 65 更新于 网络与系统管理

simple development http server with live reload capability

npmauto-collected

安装

npm
npm install -g live-server

通过 npm 安装。

Live Server ===========

This is a little development server with live reload capability. Use it for hacking your HTML/JavaScript/CSS files, but not for deploying the final site.

There are two reasons for using this:

  • AJAX requests don't work with the file:// protocol due to security restrictions, i.e. you need a server if your site fetches content through JavaScript.
  • Having the page reload automatically after changes to files can accelerate development.

You don't need to install any browser plugins or manually add code snippets to your pages for the reload functionality to work, see "How it works" section below for more information. If you don't want/need the live reload, you should probably use something even simpler, like the following Python-based one-liner:

python -m SimpleHTTPServer

Installation ------------

You need node.js and npm. You should probably install this globally.

Npm way

npm install -g live-server

Manual way

git clone https://github.com/tapio/live-server cd live-server npm install # Local dependencies if you want to hack npm install -g # Install globally

Usage from command line -----------------------

Issue the command live-server in your project's directory. Alternatively you can add the path to serve as a command line parameter.

This will automatically launch the default browser. When you make a change to any file, the browser will reload the page - unless it was a CSS file in which case the changes are applied without a reload.

Command line parameters:

  • --port=NUMBER - select port to use, default: PORT env var or 8080
  • --host=ADDRESS - select host address to bind to, default: IP env var or 0.0.0.0 ("any address")
  • --no-browser - suppress automatic web browser launching
  • --browser=BROWSER - specify browser to use instead of system default
  • --quiet | -q - suppress logging
  • --verbose | -V - more logging (logs all requests, shows all listening IPv4 interfaces, etc.)
  • --open=PATH - launch browser to PATH instead of server root
  • --watch=PATH - comma-separated string of paths to exclusively watch for changes (default: watch everything)
  • --ignore=PATH - comma-separated string of paths to ignore (anymatch-compatible definition)
  • --ignorePattern=RGXP - Regular expression of files to ignore (ie .\.jade) (DEPRECATED in favor of --ignore)
  • --no-css-inject - reload page on CSS change, rather than injecting changed CSS
  • --middleware=PATH - path to .js file exporting a middleware function to add; can be a name without path nor extension to reference bundled middlewares in middleware folder