Unplugin-console is a cross-bundler JavaScript/TypeScript plugin designed to bridge the gap between browser `console` output and your development server's terminal. It leverages the `unplugin` ecosystem to provide real-time forwarding of `console.log`, `info`, `warn`, and `error` messages from the browser directly to your Node.js terminal. Currently at version `0.0.10`, it is in an early, actively developed stage, suggesting frequent updates and potential iterative improvements. A key differentiator is its AST call-site injection approach, which ensures that browser DevTools maintain accurate source file links for logs, unlike runtime `console` overrides. It integrates seamlessly with Vite via its HMR WebSocket for optimal performance, and offers an HTTP fallback for Webpack, Rspack, and other bundlers. The plugin features robust serialization for complex data types (including circular references, Errors, BigInts), color-coded terminal output, stack trace capture, automatic disabling in production environments, and configurable log level filtering and custom prefixes, making it a powerful debugging aid.
npm install unplugin-consoleVerified import paths — ran on the pinned version, not inferred.
This Vite configuration integrates unplugin-console, forwarding all browser console messages (log, info, warn, error) to the dev-server terminal with a custom prefix.
Pin exact versions (e.g., `"unplugin-console": "0.0.10"`) or use `~` for minor updates, and thoroughly test after upgrades.
For production-like environments where logs are desired: `UnpluginConsole({ enabled: true })`.Configure a different port in the plugin options: `UnpluginConsole({ serverPort: 9000 })`.Verify and update your bundler version to meet the specified peer dependency ranges.
For Vite: `import UnpluginConsole from 'unplugin-console/vite'`. For Webpack: `const UnpluginConsole = require('unplugin-console/webpack')`.Ensure `require('unplugin-console/webpack')` is inside an array: `plugins: [require('unplugin-console/webpack')()]`.Check `NODE_ENV` (it should typically be `development` for dev servers). Ensure `levels` array includes the desired log types, e.g., `levels: ['log', 'info', 'warn', 'error']`.