BrowserSync plugin for Webpack
Easily use BrowserSync in your Webpack project.
$ npm install --save-dev browser-sync-webpack-plugin
$ yarn add --dev browser-sync-webpack-plugin
With release of 2.0.0 the plugin is expected to be used in Node v4+ environment. Support for Node v3 and lower was dropped, but you can install and use the plugin version of 1.2.0 in older environments.
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.
const BrowserSyncPlugin =moduleexports =// ...plugins:// browse to during development,// ./public directory is being servedhost: 'localhost'port: 3000server: baseDir: 'public'
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.
const BrowserSyncPlugin =moduleexports =// ...plugins:// BrowserSync options// browse to during developmenthost: 'localhost'port: 3000// proxy the Webpack Dev Server endpoint// (which should be serving on )// through BrowserSyncproxy: ''// plugin options// prevent BrowserSync from reloading the page// and let Webpack Dev Server take care of thisreload: false
Other supported plugin options are:
bs-webpack-plugin, BrowserSync instance name
undefined, BrowserSync instance init callback.
false, allows BrowserSync to inject changes inplace instead of reloading the page when changed chunks are all CSS files
Feel free to open issues to propose stuff and participate. Pull requests are also welcome.