Easily use BrowserSync in your Webpack project.
Install:
$ npm install --save-dev browser-sync-webpack-plugin
Usage:
BrowserSync will start only when you run Webpack in watch mode:
$ webpack --watch
Basic:
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-plugin');
module.exports = {
plugins: [
new BrowserSyncPlugin({
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-plugin');
module.exports = {
plugins: [
new BrowserSyncPlugin(
{
host: 'localhost',
port: 3000,
proxy: 'http://localhost:3100/'
},
{
reload: false
}
)
]
}
Another plugin options supported are name
- BrowserSync instance name
and callback
- BrowserSync instance init callback.
Contributing:
Feel free to open issues to propose stuff and participate. Pull requests are also welcome.
Licence:
MIT