|
| 1 | +# next-plugin-open-browser |
| 2 | + |
| 3 | +Automatically open browser when Next.js dev server starts. |
| 4 | + |
| 5 | +This plugin works with **webpack only**. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install --save-dev next-plugin-open-browser |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Add the plugin to your `next.config.ts`: |
| 16 | + |
| 17 | +```typescript |
| 18 | +import type { NextConfig } from "next"; |
| 19 | +import { OpenBrowserPlugin } from "next-plugin-open-browser"; |
| 20 | + |
| 21 | +const nextConfig: NextConfig = { |
| 22 | + webpack: (config, { dev, isServer }) => { |
| 23 | + // only applies in dev mode |
| 24 | + if (dev && !isServer) { |
| 25 | + config.plugins.push(new OpenBrowserPlugin()); |
| 26 | + } |
| 27 | + return config; |
| 28 | + }, |
| 29 | +}; |
| 30 | + |
| 31 | +export default nextConfig; |
| 32 | +``` |
| 33 | + |
| 34 | +Start your dev server: |
| 35 | + |
| 36 | +```bash |
| 37 | +npm run dev |
| 38 | +``` |
| 39 | + |
| 40 | +Your default browser will automatically open to `http://localhost:3000` |
| 41 | + |
| 42 | +https://github.com/user-attachments/assets/44f57d2d-4427-4751-9ed2-7a06541e8ce3 |
| 43 | + |
| 44 | +## Configuration |
| 45 | + |
| 46 | +You can pass options to customize the behavior: |
| 47 | + |
| 48 | +```typescript |
| 49 | +new OpenBrowserPlugin({ |
| 50 | + port: 3000, // custom port (default: process.env.PORT or 3000) |
| 51 | + path: '/', // custom path (default: '/') |
| 52 | + browser: 'chrome', // specific browser (default: system default) |
| 53 | + background: true // open in background without focus (default: false) |
| 54 | +}) |
| 55 | +``` |
| 56 | + |
| 57 | +## Supported Browsers |
| 58 | + |
| 59 | +The plugin automatically handles browser names across different operating systems: |
| 60 | + |
| 61 | +- **Chrome**: Works on Windows, macOS, and Linux |
| 62 | +- **Firefox**: Cross-platform support |
| 63 | +- **Edge**: Windows and macOS |
| 64 | +- **Brave**: Cross-platform support |
| 65 | +- **Browser**: Uses system default browser |
| 66 | + |
| 67 | +## Development |
| 68 | + |
| 69 | +Commands for maintainers: |
| 70 | + |
| 71 | +```bash |
| 72 | +pnpm install |
| 73 | +pnpm build |
| 74 | +pnpm test |
| 75 | +pnpm playground |
| 76 | +``` |
| 77 | + |
| 78 | +## License |
| 79 | + |
| 80 | +[MIT](./LICENSE) |
0 commit comments