webpack-contrib / webpack-bundle-analyzer

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

Feat: Allow flags to support the webpack-cli #628

Open info-arnav opened 3 months ago

info-arnav commented 3 months ago

Context

The webpack-bundle-analyzer has various options such as host which are accessible via flags with reference to webpack-cli#1838. In this PR we would be trying to support these flags in the webpack-cli, like below :

webpack build --analyze --analyze-no-open

info-arnav commented 3 months ago

And now let's use them here - https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/src/bin/analyzer.js#L27

there is an API - https://github.com/webpack/webpack/blob/main/lib/cli.js#L612 So:

  • you require options from this file
  • then use processArguments (don't forget to handle Problem)
  • then use .option(...) to create all options

on it

valscion commented 3 months ago

What are flags?

alexander-akait commented 3 months ago

@valscion We need these flags to support webpack CLI - https://github.com/webpack/webpack-cli/issues/1838, so you can use webpack build --analyze --analyze-host 127.0.0.1, so you don't need to have own CLI anymore (and can drop it in the future major release) and we will provide a better and unified API for our developers, less maintance problems for you in future too

valscion commented 3 months ago

Thanks for the background information! It would indeed be valuable to allow this tool to be used easily through webpack CLI.

In order for me to eventually be able to review this PR, I'd need to see the least amount of changes possible. That includes:

And then we'd need these:

Also, I'd like to know whether this change will indeed still be backwards-compatible (that is, releasing this would be a minor version release and not a major release). If there is no other way than doing a major release then I'm also OK with that.

All in all, I do think that this feature would make sense — but I also have some wishes as the maintainer of this project before I can accept the changes. ☺️

alexander-akait commented 3 months ago

@valscion Yeah, I will ping you when it will be ready to review

valscion commented 3 months ago

Sounds nice! Thanks!

info-arnav commented 3 months ago

@alexander-akait shall i proceed to write the tests ?