brotli-webpack-plugin
brotli-webpack-plugin copied to clipboard
Noisy output in `compress.js`
The adapter()
-function is very noisy when it comes to outputting what it does. It might make sense to use something other then console.log
in order to notify the user about what's going on. One approach would be to use the debug
-package, which lets the user decide whether he wants to see the warning or keep it suppressed: https://www.npmjs.com/package/debug
function adapter() {
// ...
try {
console.log('warning: couldn\'t find native brotli support in zlib library. trying to fall back to iltorb.');
var iltorb = require('iltorb');
return iltorb.compress;
} catch (err) {
console.log('warning: couldn\'t load iltorb library. trying to fall back to brotli.js.');
// ...
}
}
+ const debug = require('debug');
+ const warn = debug('brotli-webpack-plugin:warning');
+ const err = debug('brotli-webpack-plugin:error');
- console.log('warning: couldn\'t find native brotli support in zlib library. trying to fall back to iltorb.');
+ warn('couldn\'t find native brotli support in zlib library. trying to fall back to iltorb.');
Seems to be related:
Using plugin version 1.1.0 and Nodejs 10 LTS, run webpack --profile --json > stats.json
(webpack 4.29.6). A warning is injected before the actual json starts:
warning: couldn't find native brotli support in zlib library. trying to fall back to iltorb.
{
"errors": [],
"warnings": []
...
}
Had to remove the line manually before I could run webpack-bundle-analyzer. Switched to v 1.0.0 and it's fine now.
Webpack loaders and plugins should use this.emitWarning, not console.log
or other npm packages to log warnings. The current version of brotli-webpack-plugin is using console.log
which is polluting stdout.
the console.log
s also break the webpack-bundle-analyzer
plugin when it's used in cli mode.
Webpack loaders and plugins should use this.emitWarning, not
console.log
I went for console.warn
instead in PR #36 (which goes to stderr), because the this
isn't in scope where the logs are done, and (I think) also can't be passed in because that's available only here but we need it here.