-
Notifications
You must be signed in to change notification settings - Fork 0
Integration Guide
Complete guide to integrating DevMirror into your development workflow.
Best for new projects without existing logging.
"dev:mirror": "concurrently \"npx devmirror-cli\" \"npm run dev\""- DevMirror runs alongside your dev server
- All console output captured
- No interference with existing tools
For projects with existing loggers (like CEF logger).
"dev:mirror": "npm run dev & npx devmirror-companion"Note: Use devmirror-companion script for non-invasive operation alongside existing tools.
- Preserves existing logger functionality
- DevMirror captures additional output
- No conflicts with current setup
For applications with varying ports.
devmirror.config.json:
{
"autoDetectPort": true,
"url": "http://localhost:3000"
}- Automatically detects running dev server ports
- Waits for target application to be ready
- Configurable via DevMirror configuration
For complex interactive environments.
scripts/devmirror-background.js:
import { spawn } from 'child_process';
import net from 'net';
function checkPort(port) {
return new Promise((resolve) => {
const socket = net.createConnection(port, 'localhost');
socket.on('connect', () => {
socket.destroy();
resolve(true);
});
socket.on('error', () => resolve(false));
});
}
async function waitForPort() {
while (true) {
if (await checkPort(8555)) {
console.log('Port detected! Starting DevMirror...');
return true;
}
await new Promise(r => setTimeout(r, 1000));
}
}
async function start() {
await waitForPort();
spawn('npx', ['devmirror-cli'], {
stdio: ['ignore', 'ignore', 'inherit'],
env: { ...process.env, DEVMIRROR_SILENT: 'true' }
});
}
start().catch(console.error);{
"scripts": {
"start:mirror": "concurrently \"npx devmirror-cli\" \"react-scripts start\""
}
}{
"scripts": {
"dev:mirror": "concurrently \"npx devmirror-cli\" \"vite\""
}
}{
"scripts": {
"start:mirror": "concurrently \"npx devmirror-cli\" \"ng serve\""
}
}{
"scripts": {
"dev:mirror": "concurrently \"npx devmirror-cli\" \"next dev\""
}
}Note: Configure specific ports and other options in devmirror.config.json rather than using CLI flags.
// webpack.config.js
module.exports = {
devServer: {
port: 8080,
onListening: function(devServer) {
// DevMirror will connect when port is ready
console.log('Webpack dev server ready on port:', devServer.port);
}
}
};// vite.config.js
export default {
server: {
port: 5173,
open: true
}
};{
"scripts": {
"dev:mirror": "concurrently \"npx devmirror-cli\" \"parcel index.html\""
}
}- name: Run tests with DevMirror
run: |
npm run test:mirror
env:
DEVMIRROR_OUTPUT: ./test-logsstage('Dev with logging') {
steps {
sh 'npm run dev:mirror'
archiveArtifacts 'devmirror-logs/**/*.log'
}
}docker-compose.yml:
services:
app:
build: .
ports:
- "3000:3000"
- "9222:9222" # Chrome DevTools
environment:
- DEVMIRROR_PORT=9222
command: npm run dev:mirrorThese are supported by the companion script:
export DEVMIRROR_ENABLE=true
export DEVMIRROR_MODE=auto
export DEVMIRROR_OUTPUT=./devmirror-logs
export DEVMIRROR_CEF_PORT=8555
export DEVMIRROR_URL=http://localhost:3000
export DEVMIRROR_PARALLEL=true
export DEVMIRROR_SILENT=falseNote: The main CLI (devmirror-cli) uses configuration files, not environment variables.
Only run DevMirror in development:
{
"scripts": {
"dev": "NODE_ENV=development npm run dev:mirror || npm run dev:normal"
}
}package.json:
{
"scripts": {
"dev:local": "npx devmirror-cli --config=local.config.json",
"dev:staging": "npx devmirror-cli --config=staging.config.json",
"dev:test": "npx devmirror-cli --config=test.config.json"
}
}- Test connection manually:
curl http://localhost:9222/json- Check if port is open:
lsof -i :9222- Check VS Code Output:
View → Output → DevMirror
- Direct CLI test:
npx devmirror-cli --config=devmirror.config.json- Always use specific ports instead of auto-detection in production workflows
- Set appropriate timeouts for slow-starting applications
- Use companion mode when you have existing loggers
- Enable reconnect for hot-reloading dev servers
- Clean up logs periodically to save disk space
- Use environment-specific configs for different setups
- Document your setup in README for team members
- Use wait mode with port detection
- Increase timeout value
- Add startup delay in script
- Use companion mode
- Run on different port
- Use background script approach
- Reduce throttle settings in config
- Use smaller output buffer size
- Disable in production builds
- Use custom ports
- Check for processes using ports
- Use port ranges for auto-detection
DevMirror v0.4.82 | GitHub | Issues | VS Code Marketplace
Capture 100% of browser console output with Chrome DevTools Protocol
v0.4.82