Skip to content
Shane Osbourne edited this page Feb 2, 2014 · 8 revisions

The BrowserSync API is under development, so features are minimal at the moment.

You can however, already use it within your projects & with task runners such as Gulp using the following API.

##Usage

First, install browser-sync as a local development dependency.

npm install browser-sync --save-dev

Now use it within your project.

var browserSync = require('browser-sync');

##API ###browserSync.init( filePatterns, options );

####filePatterns

Type: String | Array

Default: null

Provide file watching patterns here

// single file pattern
browserSync.init('**/*.css');

// Multiple patterns as array
browserSync.init(['**/*.css', '*.html']);

####options

Type: Object

Default: null

There's a full list of available options here, but below are just a few common use-cases to get you started.

Static server

// Watch CSS files and launch a static-server in the root directory
browserSync.init(['css/*.css'], {
	server: {
		baseDir: './'
	}
});

Proxy

// Watch CSS files and use the proxy with your own server.
browserSync.init(['css/*.css'], {
	proxy: {
		host: 'mylocal.dev',
		port: '8000'
	}
});
Clone this wiki locally