watchify-server v1.0.2
watchify-server
This is a bare-bones development server for watchify. For a more feature-rich development server built on the same underlying modules, see budo.
Features at a glance:
- serves a default HTML index
- browserifies your entry file with incremental rebuilding
- serves your static files on port
9966or the next available port - suspends server response until the build is finished, so you are never served a stale or empty bundle
- logs build timing to
stdoutwith ndjson - build errors will be printed to the browser console by default
Install
npm install watchify-server [-g|--save]Example
Example with CLI:
watchify-server index.js --port 8000 --dir public/It might look like this with npm scripts and garnish for pretty-printing:
"devDependencies": {
"watchify-server": "^1.0.0",
"garnish": "^2.3.0"
},
"scripts": {
"start": "watchify-server src/app.js --port 8000 --dir public | garnish"
}Usage
Typically this module is used via a CLI, but it also exposes a simple JavaScript API.
CLI
Usage:
watchify-server entry.js [options] -- [browserify]
Options:
--port, -p port to listen on, default 9966
--host, -h host to listen on, default localhost
--dir, -d directory for static content, default process.cwd()
--no-debug turns off source maps
--no-error-handler turns off syntax error handling
--index optional file path to override default index.html
--title title of HTML index
--css, -s optional style sheet href, relative to --dirBrowserify options are passed after the -- full stop.
The --title and --css arguments are only applicable to the default index.html handler.
API
Note: The API does not set any default config on the browserify instance, so it is up to the developer to set debug, packageCache, and cache.
server = watchifyServer(browserify, opt, [cb])
Creates a new watchify server that wraps the specified browserify instance. Options:
entry(required) the path to the entry file to browserifysilentset totrueto disable logs
Other options are passed to watchify-middleware and serves, but defaults port to 9966 and errorHandler to true.
The returned server emits 'update' events from watchify-middleware.
The callback takes the form callback(err, ev) with the following event parameters when the server starts listening:
{
url: String // 'http://localhost:8080/'
port: Number // 8080
host: String // 'localhost'
}server = watchifyServer.fromArgs(browserifyArgs, [opt], [cb])
Creates a new watchify server from the given command-line browserify args array, with optional opt overrides and a callback.
The entry is resolved by browserify arg parsing, so opt is optional and cb can be passed as the second parameter.
See Also
- budo - a more feature-rich development server (live reload, browser launching, better error reporting, etc)
- watchify-middleware - the underlying middleware for pending server requests
- serves - the underlying server utility for this tool
- simple-html-index - the default HTML index used in this tool
- inject-lr-script - may be useful for injecting LiveReload into the
indexhandler
License
MIT, see LICENSE.md for details.
