
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
vite-plugin-browser-sync
Advanced tools
Add BrowserSync to your Vite project.
This plugin supports Vite 7 and 8.
proxy and snippet modedev, preview or build --watchnpm 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
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 defaultproxymode you need to set thebsobject.snippetmode is available inbuildWatchbut it is not recommended to use since it updates yourindex.htmlfile.- In
preview, only theproxymode is supported since it will not inject thesnippet.
// 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.
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.
| Option | Why | dev | buildWatch | preview |
|---|---|---|---|---|
| logLevel | Set to silent, use ViteJS printUrls to display BrowserSync info | ✔️ | ✔️ | ✔️ |
| open | Apply ViteJS open option | ✔️ | ✔️ | |
| codeSync | Disabled because it is already handled by ViteJS | ✔️ | ||
| online | Synced with the server host option | ✔️ | ✔️ |
proxy mode| Option | Why | dev | buildWatch | preview |
|---|---|---|---|---|
| proxy.target | Inject the right url from ViteJS | ✔️ | ✔️ | |
| proxy.ws | Force websocket proxy to make ViteJS HMR work | ✔️ | ✔️ |
snippet mode| Option | Why |
|---|---|
| logSnippet | Handled by the plugin so no need to display the snippet |
| snippet | The snippet injection is handled by the plugin |
MIT
FAQs
Add BrowserSync in your Vite project
The npm package vite-plugin-browser-sync receives a total of 6,550 weekly downloads. As such, vite-plugin-browser-sync popularity was classified as popular.
We found that vite-plugin-browser-sync demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.