webpack-contrib / webpack-bundle-analyzer

Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
MIT License
12.56k stars 483 forks source link

feat: support custom loginfo with server mode #520

Closed richerfu closed 2 years ago

richerfu commented 2 years ago

Sometimes,i will set host to be 0.0.0.0,but i won't console info with 0.0.0.0.So i need to custom log info and show better info for users.

linux-foundation-easycla[bot] commented 2 years ago

CLA Signed

The committers listed above are authorized under a signed CLA.

valscion commented 2 years ago

Hi, thanks for the pull request! How are you intending to use this change in your application?

richerfu commented 2 years ago

Actually, i create a cli tool for my team.

example for use

const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
// webpack.config.js
plugin: [
  new  BundleAnalyzerPlugin({
    host: '0.0.0.0',
    logInfo: () => {
      // some other logic
      return 'custom log info';
    }
  })
]

I will add analytics in cli tool. If i can use it like this demo.I think it's fine

valscion commented 2 years ago

copy that! I fixed. Any other suggestions?

If you could add a changelog entry to CHANGELOG.md then I think this is OK. You will also need to sign the CLA like the bot commented above:

https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/520#issuecomment-1216212707

richerfu commented 2 years ago

copy that! I fixed. Any other suggestions?

If you could add a changelog entry to CHANGELOG.md then I think this is OK. You will also need to sign the CLA like the bot commented above:

#520 (comment)

OK,i finished!

valscion commented 2 years ago

OK so the usage could look something like this, right?

plugins: [
    new  BundleAnalyzerPlugin({
      analyzerUrl: ({ listenPort, listenHost, boundAddress }) => {
        return `http://some-domain.example.com:${boundAddress.port}`;
      }
  })
]

Can we add a short documentation to the README.md about this option, too? https://github.com/webpack-contrib/webpack-bundle-analyzer#options-for-plugin

It could be below the analyzerPort value there.

Name: analyzerUrl Type: {function}, called with { listenHost: string, listenHost: string, boundAddress: server.address}. server.address comes from Node.js Default: http://${listenHost}:${boundAddress.port}. The URL printed to console with server mode

richerfu commented 2 years ago

Alright, it's my first time to contribute to this project and thanks for your guide.Thanks a lot :)

valscion commented 2 years ago

Thank you for your contributions ☺️ this PR seems good to go to me, hopefully it be useful to others, too ☺️

valscion commented 2 years ago

This has now been released in v4.6.0 ☺️