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

相关推荐
IT_陈寒4 分钟前
Java并发编程避坑指南:7个常见陷阱与性能提升30%的解决方案
前端·人工智能·后端
HBR666_18 分钟前
AI编辑器(FIM补全,AI扩写)简介
前端·ai·编辑器·fim·tiptap
牧码岛22 分钟前
服务端之NestJS接口响应message编写规范详解、写给前后端都舒服的接口、API提示信息标准化
服务器·后端·node.js·nestjs
excel23 分钟前
一文读懂 Vue 组件间通信机制(含 Vue2 / Vue3 区别)
前端·javascript·vue.js
JarvanMo26 分钟前
Flutter 应用生命周期:使用 AppLifecycleListener 阻止应用崩溃
前端
我的xiaodoujiao1 小时前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 9--基础知识 5--常用函数 3
前端·python·测试工具·ui
李鸿耀3 小时前
Flex 布局下文字省略不生效?原因其实很简单
前端
皮蛋瘦肉粥_1214 小时前
pink老师html5+css3day06
前端·css3·html5
华仔啊9 小时前
前端必看!12个JS神级简写技巧,代码效率直接飙升80%,告别加班!
前端·javascript
excel9 小时前
dep.ts 逐行解读
前端·javascript·vue.js