Skip to content

Instantly share code, notes, and snippets.

@Kirill89
Created May 27, 2018 14:06
Show Gist options
  • Save Kirill89/690268a041136013bb17be1999b39ebd to your computer and use it in GitHub Desktop.
Save Kirill89/690268a041136013bb17be1999b39ebd to your computer and use it in GitHub Desktop.
colorful output from webpack to html stream
'use strict';
const {spawn} = require('child_process');
const Convert = require('ansi-to-html');
const express = require('express');
const app = express();
const convert = new Convert({
fg: '#000',
newline: true,
escapeXML: true
});
app.get('/', (req, res) => {
const proc = spawn('npm', ['run', 'build:dev:int']);
proc.stdout.on('data', (data) => {
res.write(convert.toHtml(data.toString()));
});
proc.stderr.on('data', (data) => {
res.write(`
<span style="color: #ff0000;">
${convert.toHtml(data.toString())}
</span>
`);
});
proc.on('close', (code) => {
res.write(code);
res.end();
});
});
app.listen(3000, () => console.log('Example app listening on port 3000!'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment