在webpack配置中指定--json而不是命令行 [英] Specify --json in webpack config instead of command line

查看:86
本文介绍了在webpack配置中指定--json而不是命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过webpack-stream/gulp使用Webpack 4.我想像使用webpack --json > stats.json一样将统计信息编写为JSON文件,但要使用当前的工具.

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.

理想情况下,我只是在传递给webpack-stream的配置对象中设置选项,但是我愿意接受其他选项.

Ideally, I would simply set the option in the config object I pass to webpack-stream, but I'm open to other options.

推荐答案

就在这种情况下,我正在使用webpack-bundle-analyzer,它提供了为我写出stats.json的选项.这是配置:

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  
        }),
    ]
    // ...
}

更通用的解决方案是使用 webpack-stats-plugin .

The more general solution is to use webpack-stats-plugin.

这篇关于在webpack配置中指定--json而不是命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆