vite-plugin-browser-sync

April 12, 2026 ยท View on GitHub

npm node-current Coverage Status

vite-plugin-browser-sync

Add BrowserSync to your Vite project.

This plugin supports Vite 7 and 8.

๐Ÿš€ Features

  • โšก Fully integrated in your ViteJS environment
  • ๐Ÿ‘Œ Zero config available for common use cases
  • โœจ All the BrowserSync features
  • ๐Ÿ™Œ Support for BrowserSync proxy and snippet mode
  • ๐Ÿ”ฅ Freedom to manage BrowserSync options
  • ๐ŸŽ›๏ธ Can run on dev, preview or build --watch

๐Ÿ“ฆ Install

npm i -D vite-plugin-browser-sync

# yarn
yarn add -D vite-plugin-browser-sync

# pnpm
pnpm add -D vite-plugin-browser-sync

# bun
bun add -D vite-plugin-browser-sync

๐Ÿ‘จโ€๐Ÿ’ป Usage

By default, BrowserSync will start alongside your Vite Server in dev. It uses the proxy mode of BrowserSync based on your Vite server options: no need to pass any options to make it work!

// vite.config.js / vite.config.ts
import VitePluginBrowserSync from 'vite-plugin-browser-sync'

export default {
  plugins: [VitePluginBrowserSync()]
}

If you want to manage BrowserSync or override default behavior of this plugin, you can pass a bs object with your BrowserSync options in it:

// vite.config.js / vite.config.ts
import VitePluginBrowserSync from 'vite-plugin-browser-sync'

export default {
  plugins: [
    VitePluginBrowserSync({
      dev: {
        bs: {
          ui: {
            port: 8080
          },
          notify: false
        }
      }
    })
  ]
}

If you need the snippet mode of BrowserSync, the plugin supports it by injecting the script automatically.

// vite.config.js / vite.config.ts
import VitePluginBrowserSync from 'vite-plugin-browser-sync'

export default {
  plugins: [
    VitePluginBrowserSync({
      dev: {
        mode: 'snippet'
      }
    })
  ]
}

You can also enable the plugin on vite build --watch mode and vite preview mode.

Important

  • In buildWatch, if you use the default proxy mode you need to set the bs object.
  • snippet mode is available in buildWatch but it is not recommended to use since it updates your index.html file.
  • In preview, only the proxy mode is supported since it will not inject the snippet.
// vite.config.js / vite.config.ts
import VitePluginBrowserSync from 'vite-plugin-browser-sync'

export default {
  plugins: [
    VitePluginBrowserSync({
      dev: {
        enable: false,
      },
      preview: {
        enable: true,
      },
      buildWatch: {
        enable: true,
        bs: {
          proxy: 'http://localhost:3000',
        }
      }
    })
  ]
}

Note

For Astro users, this plugin does not work in preview mode because of overrides made by Astro.

vite-plugin-browser-sync options for BrowserSync

This plugin overrides default options from BrowserSync to avoid duplicating behaviors already handled by ViteJS. Furthermore, your ViteJS config is synced with BrowserSync.

If you want to change the overridden options you are free to do so via the bs object.

OptionWhydevbuildWatchpreview
logLevelSet to silent, use ViteJS printUrls to display BrowserSync infoโœ”๏ธโœ”๏ธโœ”๏ธ
openApply ViteJS open optionโœ”๏ธโœ”๏ธ
codeSyncDisabled because it is already handled by ViteJSโœ”๏ธ
onlineSynced with the server host optionโœ”๏ธโœ”๏ธ

For proxy mode

OptionWhydevbuildWatchpreview
proxy.targetInject the right url from ViteJSโœ”๏ธโœ”๏ธ
proxy.wsForce websocket proxy to make ViteJS HMR workโœ”๏ธโœ”๏ธ

For snippet mode

OptionWhy
logSnippetHandled by the plugin so no need to display the snippet
snippetThe snippet injection is handled by the plugin

๐Ÿ‘จโ€๐Ÿ’ผ License

MIT