webpack查看各个阶段耗时示例:

一: 简单查看编译耗时

webpack5默认是开启profile的,

c 复制代码
webpack.config.js
module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'main.js'
    },
}
c 复制代码
npm i core-js
c 复制代码
import 'core-js/stable'
src/index.js
const util = () => {
    return 'util'
}

let zhang = util()

zhang += 'zhang'
c 复制代码
打包输出信息
> demo01@1.0.0 build
> webpack

asset main.js 1010 KiB [emitted] (name: main)
runtime modules 1.13 KiB 5 modules
modules by path ./node_modules/core-js/modules/*.js 338 KiB
  ./node_modules/core-js/modules/es.symbol.js 322 bytes [built] [code generated]
  ./node_modules/core-js/modules/es.json.stringify.js 2.98 KiB [built] [code generated]
  ./node_modules/core-js/modules/es.symbol.description.js 2.54 KiB [built] [code generated]
  ./node_modules/core-js/modules/es.symbol.async-iterator.js 230 bytes [built] [code generated]
  + 295 modules
modules by path ./node_modules/core-js/internals/*.js 226 KiB
  ./node_modules/core-js/internals/path.js 85 bytes [built] [code generated]
  ./node_modules/core-js/internals/export.js 2.63 KiB [built] [code generated]
  ./node_modules/core-js/internals/global.js 649 bytes [built] [code generated]
  ./node_modules/core-js/internals/object-get-own-property-descriptor.js 1.11 KiB [built] [code generated]       
  + 256 modules
./src/demo0513/index.js 136 bytes [built] [code generated]
./node_modules/core-js/stable/index.js 11.6 KiB [built] [code generated]
webpack 5.91.0 compiled successfully in 1061 ms

可以看到编译耗时1061ms

二: 查看各个阶段耗时

c 复制代码
webpack.config.js
const SpeedMeasurePlugin = require("speed-measure-webpack-plugin");  
const smp = new SpeedMeasurePlugin();  

const config = {
    entry: './src/index.js',
    output: {
        filename: 'main.js'
    },
  mode: 'development',
}

// 使用插件包装你的配置  
module.exports = smp.wrap(config);
c 复制代码
npm i core-js
c 复制代码
src/index.js
import 'core-js/stable'

const util = () => {
    return 'util'
}

let zhang = util()

zhang += 'zhang'
c 复制代码
> demo01@1.0.0 build
> webpack

(node:24240) [DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK] DeprecationWarning: Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader
(Use `node --trace-deprecation ...` to show where the warning was created)


 SMP  ⏱
General output time took 1.038 secs

 SMP  ⏱  Loaders
modules with no loaders took 0.647 secs
  module count = 561



asset main.js 1010 KiB [compared for emit] (name: main)
runtime modules 1.13 KiB 5 modules
modules by path ./node_modules/core-js/modules/*.js 338 KiB
  ./node_modules/core-js/modules/es.symbol.js 322 bytes [built] [code generated]
  ./node_modules/core-js/modules/es.json.stringify.js 2.98 KiB [built] [code generated]
  ./node_modules/core-js/modules/es.symbol.description.js 2.54 KiB [built] [code generated]
  ./node_modules/core-js/modules/es.symbol.async-iterator.js 230 bytes [built] [code generated]
  + 295 modules
modules by path ./node_modules/core-js/internals/*.js 226 KiB
  ./node_modules/core-js/internals/path.js 85 bytes [built] [code generated]
  ./node_modules/core-js/internals/export.js 2.63 KiB [built] [code generated]
  ./node_modules/core-js/internals/global.js 649 bytes [built] [code generated]
  ./node_modules/core-js/internals/object-get-own-property-descriptor.js 1.11 KiB [built] [code generated]       
  + 256 modules
./src/demo0513/index.js 136 bytes [built] [code generated]
./node_modules/core-js/stable/index.js 11.6 KiB [built] [code generated]
webpack 5.91.0 compiled successfully in 1043 ms

从 SMP 的信息可以看到

构建耗时: 1.038s (和webpack打印的1043ms差不多)

有 561 个模块没有使用任何loader来处理,耗时0.647s

相关推荐
m0_748247551 小时前
Web 应用项目开发全流程解析与实战经验分享
开发语言·前端·php
m0_748255022 小时前
前端常用算法集合
前端·算法
真的很上进2 小时前
如何借助 Babel+TS+ESLint 构建现代 JS 工程环境?
java·前端·javascript·css·react.js·vue·html
web130933203982 小时前
vue elementUI form组件动态添加el-form-item并且动态添加rules必填项校验方法
前端·vue.js·elementui
NiNg_1_2342 小时前
Echarts连接数据库,实时绘制图表详解
前端·数据库·echarts
如若1233 小时前
对文件内的文件名生成目录,方便查阅
java·前端·python
滚雪球~4 小时前
npm error code ETIMEDOUT
前端·npm·node.js
沙漏无语4 小时前
npm : 无法加载文件 D:\Nodejs\node_global\npm.ps1,因为在此系统上禁止运行脚本
前端·npm·node.js
supermapsupport4 小时前
iClient3D for Cesium在Vue中快速实现场景卷帘
前端·vue.js·3d·cesium·supermap
brrdg_sefg4 小时前
WEB 漏洞 - 文件包含漏洞深度解析
前端·网络·安全