问题
I'm using Webpack 4 via webpack-stream / gulp. I'd like to write stats as a JSON file, like I would with webpack --json > stats.json
, but using my current tooling.
Ideally, I would simply set the option in the config object I pass to webpack-stream, but I'm open to other options.
回答1:
It just so happens I'm using webpack-bundle-analyzer, which provides the option to write out stats.json for me. Here's the config:
{
// ...
plugins: [
new analyzer.BundleAnalyzerPlugin({
// writes to <webpack output dir>/stats.json by default
generateStatsFile: true
}),
]
// ...
}
The more general solution is to use webpack-stats-plugin.
来源:https://stackoverflow.com/questions/50876533/specify-json-in-webpack-config-instead-of-command-line