-
Install the plugin:
pnpm add webpack-log-forward-plugin --save-dev
-
Add to your webpack config:
const WebpackLogForwardPlugin = require('webpack-log-forward-plugin'); module.exports = { mode: 'development', devServer: { // your dev server config }, plugins: [ new WebpackLogForwardPlugin() ] };
-
Start your dev server:
webpack serve
-
Open your browser and use console methods:
console.log('Hello from browser!'); console.error('This error will appear in terminal');
new WebpackLogForwardPlugin({
logTypes: ['error', 'warn'],
prefix: '[App Errors]'
})new WebpackLogForwardPlugin({
prefix: '🚀 [Frontend]',
includeTimestamp: false
})const isDevelopment = process.env.NODE_ENV === 'development';
module.exports = {
mode: isDevelopment ? 'development' : 'production',
plugins: [
...(isDevelopment ? [
new WebpackLogForwardPlugin({
logTypes: ['error', 'warn', 'info'],
prefix: '[MyApp]'
})
] : [])
]
};new WebpackLogForwardPlugin({
// Only forward specific log types
logTypes: ['error', 'warn', 'info'],
// Custom prefix
prefix: '[MyApp Browser]',
// Include timestamps
includeTimestamp: true,
// Enable/disable plugin
enabled: true
})When you use console.log('Hello World') in your browser, you'll see:
[Browser] LOG: 2024-01-15T10:30:45.123Z Hello World
- LOG (cyan):
console.log() - INFO (green):
console.info() - WARN (yellow):
console.warn() - ERROR (red):
console.error() - DEBUG (magenta):
console.debug()
-
Navigate to the example directory:
cd example pnpm install pnpm start -
Open your browser to
http://localhost:3000 -
Click the test buttons or open browser console and run:
console.log('Test message'); console.error('Test error'); console.warn('Test warning');
-
Check your terminal for the forwarded logs
-
Check webpack mode:
// Must be development mode mode: 'development'
-
Check dev server configuration:
// Must have devServer config devServer: { // your config }
-
Check plugin is enabled:
new WebpackLogForwardPlugin({ enabled: true // default is true })
- Check browser console for errors
- Verify the script is injected (check Network tab for
log-forward.js) - Check terminal for middleware errors
-
Limit log types:
logTypes: ['error', 'warn'] // Only forward errors and warnings
-
Disable timestamps:
includeTimestamp: false
// webpack.config.js (eject or use react-app-rewired)
const WebpackLogForwardPlugin = require('webpack-log-forward-plugin');
module.exports = function override(config, env) {
if (env === 'development') {
config.plugins.push(
new WebpackLogForwardPlugin({
logTypes: ['error', 'warn', 'info'],
prefix: '[React App]'
})
);
}
return config;
};// vue.config.js
const WebpackLogForwardPlugin = require('webpack-log-forward-plugin');
module.exports = {
configureWebpack: {
plugins: [
new WebpackLogForwardPlugin({
logTypes: ['error', 'warn'],
prefix: '[Vue App]'
})
]
}
};// next.config.js
const WebpackLogForwardPlugin = require('webpack-log-forward-plugin');
module.exports = {
webpack: (config, { dev, isServer }) => {
if (dev && !isServer) {
config.plugins.push(
new WebpackLogForwardPlugin({
logTypes: ['error', 'warn', 'info'],
prefix: '[Next.js]'
})
);
}
return config;
},
};