webpack-configurator icon indicating copy to clipboard operation
webpack-configurator copied to clipboard

Pretty print config

Open vjpr opened this issue 9 years ago • 2 comments

Provide a print method which uses the prettyjson module to print YAML-like output of the webpack config.

Why?

  • If you print a normal config object it will not show the names of the plugins, just their instance vars.
  • prettyjson looks nicer and is easier to read.

vjpr avatar Oct 27 '15 22:10 vjpr

I quite like this idea. I've never used the prettyjson module before but it looks promising. This has always been a problem in projects that required complex configuration. My hack solution would either involve stringifying or using node-inspector to see the raw output when resolving.

My only questions are:

  • Does prettyjson handle regular expression objects? Previously, stringifying would simply return an empty object.
  • Does prettyjson handle instance names (such as DefinePlugin)?
  • How do you imagine this working? Would you expect another method (e.g. .print()) or something else?

lewie9021 avatar Oct 27 '15 23:10 lewie9021

Does prettyjson handle regular expression objects? Previously, stringifying would simply return an empty object.

Yep.

Does prettyjson handle instance names (such as DefinePlugin)?

Nope.

This method I wrote does:

function prettifyWebpackConfig(config) {
  const prettyConfig = _.clone(config, true)
  prettyConfig.plugins = config.plugins.map(p => {
    return {name: p.constructor.name, settings: p}
  })
  return require('prettyjson').render(prettyConfig)
}

How do you imagine this working? Would you expect another method (e.g. .print()) or something else?

.print() makes the most sense if we are printing with prettyjson. Maybe a class method too in order to not have to run resolve twice.

Also off-topic, maybe .toJSON() as an alias for resolve().

vjpr avatar Oct 28 '15 01:10 vjpr