Last active
November 16, 2016 21:44
-
-
Save earnubs/b0917bebda129525ce2bd70d1ad39ba0 to your computer and use it in GitHub Desktop.
custom webpack logger (talisker)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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