koa-browser-sync
BrowserSync middleware for Koa.
Use this middleware to automatically inject the necessary browser-sync
snippet into your HTML pages.
Installation
npm install koa-browser-sync --save-dev
Usage
There is two ways to use this module.
browser-sync
and inject the snippet with init: true
(This option is set to false by default).
1) Start See the BrowserSync docs for initialization options.
var koa = ;var app = ; if appenv == 'development' // Use init option to start the server, default: false // Other options are passed directly to browser-sync // ex: {init:true, files: ["app/css/**/*.css"], logConnections: false} app; app; app;
browser-sync
from a build tool like gulp, grunt, etc)
2) Get the snippet from BROWSERSYNC_SNIPPET environment variable (usefull to start var koa = ;var app = ; if appenv == 'development' // No options or {init: false} // The snippet must be provide by BROWSERSYNC_SNIPPET environment variable app
Notes
- All the options are passed directly to
browser-sync
. - Injection only happens on responses with a Content-Type header of
text/html
and containing a closing body tag</body>
.