知海

ProfilingPlugin 插件

webpackjsorg-main插件参考

ProfilingPlugin 插件

生成包含插件执行时间统计的 Chrome profile 文件。默认输出 events.json 文件。可以通过 outputPath 选项提供自定义文件路径。

注意:ProfilingPlugin 仅接受绝对路径。

选项

  • outputPath:自定义输出文件(json)的绝对路径。

用法:默认

js 复制代码
new webpack.debug.ProfilingPlugin();

用法:自定义 outputPath

js 复制代码
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

new webpack.debug.ProfilingPlugin({
  outputPath: path.join(__dirname, "profiling/profileEvents.json"),
});

要查看 profile 文件:

  1. 使用 ProfilingPlugin 运行 webpack。
  2. 打开 Chrome,进入 DevTools,然后转到 Performance 标签页(原 Timeline)。
  3. 将生成的文件(默认是 events.json)拖放到 profiler 中。

然后它将显示每个插件的时间线统计和调用!

帮助我们改进文档

发现翻译问题或内容错误?请告诉我们。