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

相关推荐
栈老师不回家17 分钟前
Vue 计算属性和监听器
前端·javascript·vue.js
前端啊龙23 分钟前
用vue3封装丶高仿element-plus里面的日期联级选择器,日期选择器
前端·javascript·vue.js
一颗松鼠27 分钟前
JavaScript 闭包是什么?简单到看完就理解!
开发语言·前端·javascript·ecmascript
小远yyds1 小时前
前端Web用户 token 持久化
开发语言·前端·javascript·vue.js
吕彬-前端2 小时前
使用vite+react+ts+Ant Design开发后台管理项目(五)
前端·javascript·react.js
学前端的小朱2 小时前
Redux的简介及其在React中的应用
前端·javascript·react.js·redux·store
guai_guai_guai2 小时前
uniapp
前端·javascript·vue.js·uni-app
bysking3 小时前
【前端-组件】定义行分组的表格表单实现-bysking
前端·react.js
王哲晓3 小时前
第三十章 章节练习商品列表组件封装
前端·javascript·vue.js
fg_4113 小时前
无网络安装ionic和运行
前端·npm