跳到主要内容

performance

performance 配置如何展示性能提示。例如,如果一个资源超过 250kb,webpack 会对此输出一个警告来通知你。

performance.hints


performance.hints 打开/关闭提示。此外,当找到提示时,告诉 webpack 抛出一个错误或警告。此属性默认设置为 "warning"。

performance.hints 配置如下:

  • 展示警告

    performance: {
    hints: 'warning',
    },
  • 展示错误 : 通知你这是体积大的资源。在生产环境构建时,我们推荐使用 hints: "error",有助于防止把体积巨大的 bundle 部署到生产环境,从而影响网页的性能。

    performance: {
    hints: 'error',
    },
  • 不展示警告或者错误提示

    performance: {
    hints: 'false',
    },

performance.assetFilter


performance.assetFilter 此属性允许 webpack 控制用于计算性能提示的文件

performance.assetFilter 配置如下:

performance: {
assetFilter: function (assetFilename) {
return assetFilename.endsWith(".css") || assetFilename.endsWith(".js");
}
}

performance.maxAssetSize


资源(asset)是从 webpack 生成的任何文件。此选项根据单个资源体积(单位: bytes),控制 webpack 何时生成性能提示。

performance.maxAssetSize 配置如下:

performance: {
maxAssetSize: 100000,
}

performance.maxEntrypointSize


入口起点表示针对指定的入口,对于所有资源,要充分利用初始加载时(initial load time)期间。此选项根据入口起点的最大体积,控制 webpack 何时生成性能提示。

performance.maxEntrypointSize 配置如下:

performance: {
maxEntrypointSize: 400000,
}