brotli-webpack-plugin icon indicating copy to clipboard operation
brotli-webpack-plugin copied to clipboard

Noisy output in `compress.js`

Open PAkerstrand opened this issue 5 years ago • 4 comments

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

1____project_spt_hyperion__bash_

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.');

PAkerstrand avatar Mar 05 '19 09:03 PAkerstrand

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.

ViktorZhurbin avatar Mar 13 '19 18:03 ViktorZhurbin

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.

keeganstreet avatar May 08 '19 00:05 keeganstreet

the console.logs also break the webpack-bundle-analyzer plugin when it's used in cli mode.

gex avatar May 08 '19 13:05 gex

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.

nh2 avatar Jun 28 '19 03:06 nh2