Skip to content

Instantly share code, notes, and snippets.

@earnubs
Last active November 16, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earnubs/b0917bebda129525ce2bd70d1ad39ba0 to your computer and use it in GitHub Desktop.
Save earnubs/b0917bebda129525ce2bd70d1ad39ba0 to your computer and use it in GitHub Desktop.
custom webpack logger (talisker)
webpackApp.use(webpackDevMiddleware(compiler, {
contentBase: webpackDevUrl.href,
quiet: false,
hot: true,
noInfo: false,
stats: {
colors: false,
chunks: false,
children: false
},
headers: { 'Access-Control-Allow-Origin': '*' },
publicPath: webpackConfig.output.publicPath,
log: logger.info.bind(logger),
reporter: (reporterOptions) => {
const { state, stats, options } = reporterOptions;
const obj = stats.toJson({
chunks: false,
colors: false,
children: false,
modules: false,
chunkModules: false,
source: false
});
if (state) {
let displayStats = (!options.quiet && options.stats !== false);
if (displayStats && !(stats.hasErrors() || stats.hasWarnings()) &&
options.noInfo)
{
displayStats = false;
}
if (displayStats) {
if (obj.hash) {
options.log('stats', {
hash: obj.hash,
version: obj.version,
time: obj.time + 'ms'
});
}
if (obj.assets && obj.assets.length > 0) {
obj.assets.forEach((asset) => {
options.log('stats', {
asset: asset.name,
size: prettyBytes(asset.size)
});
});
}
}
if (!options.noInfo && !options.quiet) {
options.log('bundle is now VALID.');
}
} else {
options.log('bundle is now INVALID.');
}
}
}));
webpackApp.use(webpackHotMiddleware(compiler, {
log: logger.info.bind(logger)
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment