1.0.1 • Published 7 years ago

browser-sync-webpack v1.0.1

Weekly downloads
41
License
MIT
Repository
github
Last release
7 years ago

browser-sync-webpack

Last version Dependency status Dev Dependencies Status NPM Status Donate

BrowserSync under Webpack

Install

$ npm install browser-sync-webpack --save

Usage

Basic

BrowserSync will start only when you run Webpack in watch mode:

$ webpack --watch

If you're not using Webpack Dev Server, you can make BrowserSync to serve your project. The setup is pretty easy: just pass the BrowserSync options to the plugin as the first argument.

In your webpack.config.js:

var BrowserSyncPlugin = require('browser-sync-webpack');

module.exports = {
  // ...
  plugins: [
    new BrowserSyncPlugin({
      // browse to http://localhost:3000/ during development,
      // ./public directory is being served
      host: 'localhost',
      port: 3000,
      server: { baseDir: ['public'] }
    })
  ]
}

Advanced

The advanced usage is about using Webpack Dev Server with BrowserSync in order to use awesome features of both.

To achieve this, BrowserSync offers the proxy option. So, basically, you are about to proxy the output from the Webpack Dev Server through BrowserSync to get the best out of both.

In your webpack.config.js:

var BrowserSyncPlugin = require('browser-sync-webpack');

module.exports = {
  // ...
  plugins: [
    new BrowserSyncPlugin(
      // BrowserSync options
      {
        // browse to http://localhost:3000/ during development
        host: 'localhost',
        port: 3000,
        // proxy the Webpack Dev Server endpoint
        // (which should be serving on http://localhost:3100/)
        // through BrowserSync
        proxy: 'http://localhost:3100/'
      },
      // plugin options
      {
        // prevent BrowserSync from reloading the page
        // and let Webpack Dev Server take care of this
        reload: false
      }
    )
  ]
}

Another plugin options supported are name - BrowserSync instance name and callback - BrowserSync instance init callback.

License

MIT © Kiko Beats.