browser-sync-webpack-plugin

Easily use BrowserSync in your Webpack project.

Github星跟蹤圖

BrowserSync plugin for Webpack

Easily use BrowserSync in your Webpack project.

Install:

$ npm install --save-dev browser-sync-webpack-plugin

or

$ 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.

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:

const BrowserSyncPlugin = require('browser-sync-webpack-plugin')

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:

const BrowserSyncPlugin = require('browser-sync-webpack-plugin')

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
      }
    )
  ]
}

Other supported plugin options are:

  • name - default: bs-webpack-plugin, BrowserSync instance name
  • callback - default: undefined, BrowserSync instance init callback.
  • injectCss - default: false, allows BrowserSync to inject changes inplace instead of reloading the page when changed chunks are all CSS files

Contributing:

Feel free to open issues to propose stuff and participate. Pull requests are also welcome.

Licence:

MIT

主要指標

概覽
名稱與所有者Va1/browser-sync-webpack-plugin
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2015-06-26 09:36:15
推送於2024-08-15 08:09:52
最后一次提交2024-08-15 10:09:51
發布數11
最新版本名稱v2.3.0 (發布於 )
第一版名稱v1.0.3 (發布於 )
用户参与
星數371
關注者數6
派生數45
提交數66
已啟用問題?
問題數75
打開的問題數16
拉請求數14
打開的拉請求數2
關閉的拉請求數9
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?