Skip to content

Provide option to set toJson options #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chrisbateman opened this issue Dec 21, 2016 · 4 comments · Fixed by #31
Closed

Provide option to set toJson options #18

chrisbateman opened this issue Dec 21, 2016 · 4 comments · Fixed by #31

Comments

@chrisbateman
Copy link

When you generate stats with the Webpack CLI - it passes a particular set of "outputOptions" to toJson(). This results in different output than calling it without any options, which this plugin currently does.

Providing the ability to pass the custom outputOptions into the toJson() call would allow users to customize the results, or make them match the default Webpack results.

@ryan-roemer
Copy link
Member

Hmm... Already you could do something like:

var StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;

module.exports = {
  plugins: [
    new StatsWriterPlugin({
      transform: function (data, opts) {
        var stats = opts.compiler.getStats().toJson(/* YOUR OPTIONS */)
        return DO_SOMETHING_WITH_CUSTOMIZED_STATS(stats);
      }
    })
  ]
};

to get you by, bypassing the data and using the compiler directly.

But, I would potentially be open to a PR with an additional options field to punch into the toJson() call. Feel free to strawman it here first!

@chrisbateman
Copy link
Author

Shoot, I didn't notice that the transform function provides the compiler. So yeah, this could work:

new StatsWriterPlugin({
  transform: function(data, opts) {
    let stats = opts.compiler.getStats().toJson({chunkModules: true});
    return JSON.stringify(stats, null, 2); 
  }
});

But it does require you to learn about compiler.getStats().toJson() and JSON.stringify(stats, null, 2) which this plugin covers for you otherwise.

An option to pass in the output options might look like this:

new StatsWriterPlugin({
  fields: null,
  stats: {chunkModules: true}
});

Webpack's docs/config uses the property stats but internally it's called outputOptions. Either could work.

@chrisbateman
Copy link
Author

Either way, thanks for the quick response!

@ryan-roemer
Copy link
Member

Yeah, I'd be open to a PR that adds a field stats that is straight passed to toJson() with links to the documentation you linked in. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants