-
Start the example server:
cd example pnpm start -
Open your browser to
http://localhost:3001 -
Open browser console (F12) and run these commands:
console.log('Hello from browser!'); console.error('This is an error message'); console.warn('This is a warning message'); console.info('This is an info message'); console.debug('This is a debug message');
-
Check your terminal - you should see colored log messages like:
[Browser] LOG: 2024-01-15T10:30:45.123Z Hello from browser! [Browser] ERROR: 2024-01-15T10:30:45.124Z This is an error message [Browser] WARN: 2024-01-15T10:30:45.125Z This is a warning message
-
Start the example server:
cd example pnpm start -
Open
http://localhost:3001in your browser -
Click the test buttons:
- "Test Console Logs" - Tests all console methods
- "Test Errors" - Tests unhandled errors and promise rejections
- "Test Objects" - Tests logging objects and arrays
-
Create a simple HTML file:
<!DOCTYPE html> <html> <head> <title>Test Plugin</title> </head> <body> <h1>Test WebpackLogForwardPlugin</h1> <script> console.log('Page loaded!'); console.error('Test error'); console.warn('Test warning'); </script> </body> </html>
-
Add the plugin to your webpack config:
const { WebpackLogForwardPlugin } = require('webpack-log-forward-plugin'); module.exports = { mode: 'development', devServer: { static: './public', port: 3000 }, plugins: [ new WebpackLogForwardPlugin({ logTypes: ['log', 'error', 'warn'], prefix: '[MyApp]' }) ] };
-
Start your dev server and test
-
Terminal shows colored logs:
- Cyan for
console.log() - Green for
console.info() - Yellow for
console.warn() - Red for
console.error() - Magenta for
console.debug()
- Cyan for
-
Log format:
[Browser] LOG: 2024-01-15T10:30:45.123Z Your message here -
Script injection:
- Check browser Network tab for
log-forward.js - Check page source for
<script src="/log-forward.js"></script>
- Check browser Network tab for
-
No logs appearing in terminal:
- Check if webpack is in development mode
- Check if dev server is configured
- Check browser console for errors
-
Script not injected:
- Check if
log-forward.jsis being served - Check if HTML contains the script tag
- Check if
-
Plugin not working:
- Ensure you're using the correct import:
const { WebpackLogForwardPlugin } = require('webpack-log-forward-plugin') - Check that the plugin is built:
pnpm run build
- Ensure you're using the correct import:
-
Verify plugin is loaded:
// In your webpack config console.log('Plugin loaded:', WebpackLogForwardPlugin);
-
Check dev server configuration:
// In your webpack config console.log('Dev server config:', devServer);
-
Test middleware endpoint:
curl -X POST http://localhost:3001/__webpack_log_forward__ \ -H "Content-Type: application/json" \ -d '{"type":"log","message":"test","timestamp":"","prefix":"[Test]"}'
// Test basic logging
console.log('Test message');
console.error('Test error');
console.warn('Test warning');
// Test objects
console.log('Object:', { name: 'John', age: 30 });
console.info('Array:', [1, 2, 3, 4, 5]);
// Test errors
setTimeout(() => {
throw new Error('Test unhandled error');
}, 1000);
// Test promise rejections
setTimeout(() => {
Promise.reject(new Error('Test promise rejection'));
}, 2000);When you run the tests, you should see output like this in your terminal:
[Browser] LOG: 2024-01-15T10:30:45.123Z Page loaded!
[Browser] ERROR: 2024-01-15T10:30:45.124Z Test error
[Browser] WARN: 2024-01-15T10:30:45.125Z Test warning
[Browser] LOG: 2024-01-15T10:30:45.126Z Object: {"name":"John","age":30}
[Browser] INFO: 2024-01-15T10:30:45.127Z Array: [1,2,3,4,5]
[Browser] ERROR: 2024-01-15T10:30:46.128Z Test unhandled error
[Browser] ERROR: 2024-01-15T10:30:47.129Z Test promise rejection
# Build the plugin
pnpm run build
# Run tests
pnpm test
# Start example server
cd example && pnpm start
# Test in browser
open http://localhost:3001Test different configurations:
// Test only errors and warnings
new WebpackLogForwardPlugin({
logTypes: ['error', 'warn'],
prefix: '[Errors Only]'
})
// Test without timestamps
new WebpackLogForwardPlugin({
includeTimestamp: false,
prefix: '[No Timestamp]'
})
// Test custom prefix
new WebpackLogForwardPlugin({
prefix: '🚀 [MyApp]'
})