Socket
Socket
Sign inDemoInstall

connect-browser-sync

Package Overview
Dependencies
648
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    connect-browser-sync

Connect middleware for BrowserSync.


Version published
Weekly downloads
1.4K
increased by8.62%
Maintainers
1
Install size
268 kB
Created
Weekly downloads
 

Readme

Source

connect-browser-sync

Connect middleware for BrowserSync.

Use this middleware to automatically inject the necessary BrowserSync <script> tags into your HTML pages. Alternatively, you can integrate BrowserSync with your app using Gulp or Grunt.

NPM version Build Status Dependency Status

Usage

Assuming you will only use BrowserSync in development:

npm install browser-sync --save-dev
npm install connect-browser-sync --save-dev
// app.js
var express = require('express');
var app = express();

// Other configuration...

if (app.get('env') === 'development') {
  var browserSync = require('browser-sync');
  var bs = browserSync.create().init({ logSnippet: false });
  app.use(require('connect-browser-sync')(bs));
}


// Routes and handlers...

See the BrowserSync API docs for initialization options.

Notes

  • You must use version 2.0.0 or greater of the browser-sync package.
  • The app.use statement must come before any handlers that you want to integrate with BrowserSync. This includes both dynamic route handlers and static asset handlers.
  • Injection only happens on responses with a Content-Type header of text/html and content containing a </body> or </head> tag.

Compatibility

BrowserSync 1.x

If you need to use BrowserSync 1.x, use version 1.0.2 of this package.

Turbolinks and BrowserSync can conflict (see turbolinks#147 and browser-sync#977). As a workaround, you can inject the BrowserSync tags into <head> instead.

To inject the tags into <head>, specify { injectHead: true }:

if (app.get('env') === 'development') {
  var browserSync = require('browser-sync');
  var bs = browserSync.create().init({ logSnippet: false });
  app.use(require('connect-browser-sync')(bs, { injectHead: true }));
}

Example

See the example folder.

License

Copyright © 2014 Chris Schmich
MIT License, See LICENSE for details.

Keywords

FAQs

Last updated on 01 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc