代码之家  ›  专栏  ›  技术社区  ›  jakub.g

如何将有效的网页包生成配置打印到控制台?

  •  2
  • jakub.g  · 技术社区  · 6 年前

    我有一个复杂的webpack配置设置(通过多个配置文件合并动态设置),我想看看webpack使用的最终配置是什么,即所有这些和默认设置合并的结果。

    2 回复  |  直到 6 年前
        1
  •  10
  •   jakub.g    6 年前

    let config = {
      // ...
      plugins: [
        // ...
        { // anonymous plugin
          apply(compiler) {
            compiler.hooks.beforeRun.tapAsync('MyCustomBeforeRunPlugin', function(compiler, callback) {
              // debugger
              console.dir(compiler.options)
              callback()
            })
          },
        }
      ]
    }
    

    当您取消注释 debugger 语句并使用 --inspect-brk 旗帜( node --inspect-brk run-webpack.js chrome://inspect/ 页(用于检查无法序列化到控制台的函数和对象实例)。

        2
  •  3
  •   Ali Ghali    6 年前

    对我来说,最有效的是,我在export语句之前创建了我想要的所有配置,然后导出了一个可以控制台和返回配置的函数

    module.exports = () => {
      // I have two configs to export and wanted to see the rules
      // you may not see the nested objects then you have to console log them
      // directly
    
      console.log(config[0].module.rules);
      console.log(config[1].module.rules);
      return config;
    };
    
        3
  •  3
  •   boatcoder    4 年前

    最简单的方法是使用 webpack-config-dump-plugin

    npm页面上有安装和使用说明。