Webpack progress using node.js API

后端 未结 3 1866
[愿得一人]
[愿得一人] 2021-02-05 04:21

Is there currently a way to access webpack\'s progress while using the node.js API? I\'m familiar with the --progress flag using the CLI.

3条回答
  •  被撕碎了的回忆
    2021-02-05 04:24

    The Webpack CLI uses the ProgressPlugin to log the progress of a compilation.

    var ProgressPlugin = require('webpack/lib/ProgressPlugin');
    
    var compiler = webpack(config);
    
    compiler.apply(new ProgressPlugin(function(percentage, msg) {
      console.log((percentage * 100) + '%', msg);
    }));
    
    compiler.run(function(err, stats) {
      // ...
    });
    

    Here is a link to the Compiler documentation and the ProgressPlugin documentation.

提交回复
热议问题