webpack-configurator
webpack-configurator copied to clipboard
Pretty print config
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.
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?
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()
.