当前位置: 首页 > article >正文

【前端优化】使用speed-measure-webpack-plugin分析前端运行、打包耗时,优化项目

记录下

项目安装speed-measure-webpack-plugin

打包分析:

修改vue.config.js文件
speed-measure-webpack-plugin进行构建速度分析,需要包裹整个 configureWebpack 配置

const originalConfig = {publicPath: '/',assetsDir: 'assets',parallel: true,devServer: {hot: true},lintOnSave: false,runtimeCompiler: true,chainWebpack: (config) => {config.resolve.alias.set('@', resolve('src')).set('@views', resolve('src/views')).set('@comp', resolve('src/components')).set('@root', resolve('/'))config.module.rule('images').test(/\.(png|jpe?g|gif|svg)(\?.*)?$/).type('asset').parser({dataUrlCondition: {maxSize: 8 * 1024 // 8KB以下转base64 //2560}})//   .set('generator', {//     filename: 'img/[name].[hash:8][ext]'//   })config.module.rule('images').use('image-webpack-loader').loader('image-webpack-loader').options({bypassOnDebug: true}).end()},configureWebpack: {cache: {type: 'filesystem', // 使用文件缓存buildDependencies: {config: [__filename] // 缓存依赖},allowCollectingMemory: true,maxMemoryGenerations: 1},optimization: {minimizer: minimizer,removeEmptyChunks: process.env.NODE_ENV === 'production',splitChunks: splitChunks},plugins: plugins,module: {noParse: /jquery/,rules: [{test: /\.js$/,include: path.resolve(__dirname, 'src'),exclude: /node_modules/,use: [{loader: 'thread-loader',options: {workers: cpuCount,workerParallelJobs: 20,workerNodeArgs: ['--max-old-space-size=1024'] // 限制子进程内存// poolTimeout: 2000 // 空闲时自动关闭}},{loader: 'babel-loader',options: {babelrc: true,cacheDirectory: true}}]}]}},css: {loaderOptions: {// You need to configure a global variable if you want to use it in a componentscss: {additionalData: '@import "~@/assets/css/variables.scss";'}}},// 设为false打包时不生成.map文件productionSourceMap: false
}
module.exports = {...originalConfig,configureWebpack: smp.wrap(originalConfig.configureWebpack)
}

npm run dev运行,获取分析:

SMP  ⏱
General output time took 7 mins, 42.001 secsSMP  ⏱  Plugins
DefinePlugin took 0 secs
TerserPlugin took 0 secsSMP  ⏱  Loaders
@vue/vue-loader-v15, and
mini-css-extract-plugin, and
css-loader, and
postcss-loader, and
sass-loader, and
@vue/vue-loader-v15 took 4 mins, 58.75 secsmodule count = 2340
css-loader, and
@vue/vue-loader-v15, and
postcss-loader, and
sass-loader, and
@vue/vue-loader-v15 took 4 mins, 53.93 secsmodule count = 1170
@vue/vue-loader-v15, and
thread-loader, and
babel-loader, and
thread-loader, and
babel-loader, and
@vue/vue-loader-v15 took 3 mins, 22.91 secsmodule count = 3430
mini-css-extract-plugin, and
css-loader, and
postcss-loader took 2 mins, 41.67 secsmodule count = 21
thread-loader, and
babel-loader, and
thread-loader, and
babel-loader took 2 mins, 33.61 secsmodule count = 404
mini-css-extract-plugin, and
css-loader, and
postcss-loader, and
sass-loader took 2 mins, 12.24 secsmodule count = 4
modules with no loaders took 2 mins, 2.27 secsmodule count = 2244
image-webpack-loader took 1 min, 36.096 secsmodule count = 327
@vue/vue-loader-v15 took 1 min, 31.51 secsmodule count = 5127
css-loader, and
postcss-loader took 1 min, 13.14 secsmodule count = 21
css-loader, and
postcss-loader, and
sass-loader took 50.62 secsmodule count = 4
@vue/vue-loader-v15, and
mini-css-extract-plugin, and
css-loader, and
postcss-loader, and
@vue/vue-loader-v15 took 49.91 secsmodule count = 6
css-loader, and
@vue/vue-loader-v15, and
postcss-loader, and
@vue/vue-loader-v15 took 15.11 secsmodule count = 3
html-webpack-plugin took 1.9 secsmodule count = 1
raw-loader took 0.819 secsmodule count = 1
script-loader took 0.032 secsmodule count = 1



修改配置

1.图片处理仅在生产环境使用

    if (process.env.NODE_ENV === 'production') {config.module.rule('images').test(/\.(png|jpe?g|gif|svg)(\?.*)?$/).type('asset').parser({dataUrlCondition: {maxSize: 8 * 1024 // 8KB以下转base64 //2560}})//   .set('generator', {//     filename: 'img/[name].[hash:8][ext]'//   })config.module.rule('images').use('image-webpack-loader').loader('image-webpack-loader').options({bypassOnDebug: true}).end()} else {config.module.rule('images').uses.delete('image-webpack-loader') // 移除图像压缩}
  1. scss设置
  css: {loaderOptions: {// You need to configure a global variable if you want to use it in a componentscss: {implementation: require('sass'),additionalData: '@import "~@/assets/css/variables.scss";'}}},
  1. 改用esbuild-loader,用了之后是要快一点,但这个速度感觉还是不对啊
// 删除原有的babel-loader配置config.module.rules.delete('js')// 添加esbuild-loaderconfig.module.rule('js').test(/\.(js|mjs|jsx)$/)// .exclude.add(/node_modules/)// .end().use('esbuild-loader').loader('esbuild-loader').options({target: 'es2015',loader: 'jsx'})
thread-loader, and 
babel-loader took 1 min, 23.34 secsmodule count = 374
-------
esbuild-loader took 52.51 secsmodule count = 395

再次优化后,打包速度提升:

 SMP  ⏱  
General output time took 4 mins, 5.18 secsSMP  ⏱  Plugins
DefinePlugin took 0.002 secsSMP  ⏱  Loaders
css-loader, and 
@vue/vue-loader-v15, and 
postcss-loader, and 
sass-loader, and 
@vue/vue-loader-v15 took 3 mins, 16.68 secsmodule count = 1170
@vue/vue-loader-v15 took 2 mins, 11.74 secsmodule count = 5127
@vue/vue-loader-v15, and 
esbuild-loader, and 
@vue/vue-loader-v15 took 1 min, 50.85 secsmodule count = 3430
modules with no loaders took 1 min, 27.56 secsmodule count = 2609
css-loader, and 
postcss-loader took 1 min, 11.28 secsmodule count = 21
css-loader, and 
postcss-loader, and 
sass-loader took 1 min, 8.42 secsmodule count = 4
esbuild-loader took 52.51 secsmodule count = 395
css-loader, and 
@vue/vue-loader-v15, and 
postcss-loader, and 
@vue/vue-loader-v15 took 8.85 secsmodule count = 3
@vue/vue-loader-v15, and 
vue-style-loader, and 
css-loader, and 
postcss-loader, and 
sass-loader, and 
@vue/vue-loader-v15 took 2.93 secsmodule count = 2340
vue-style-loader, and 
css-loader, and 
postcss-loader took 0.373 secsmodule count = 21
vue-style-loader, and 
css-loader, and 
postcss-loader, and 
sass-loader took 0.197 secsmodule count = 4
html-webpack-plugin took 0.141 secsmodule count = 1
@vue/vue-loader-v15, and 
vue-style-loader, and 
css-loader, and 
postcss-loader, and 
@vue/vue-loader-v15 took 0.016 secsmodule count = 6

但CSS相关加载器耗时还是非常长,没搜到怎么优化。。。。


webpack5新增了一个懒加载属性 lazyCompilation, 还可以使用 DllPlugin 进行分包,都能提升运行速度; 后面看看

相关文章:

【前端优化】使用speed-measure-webpack-plugin分析前端运行、打包耗时,优化项目

记录下 项目安装speed-measure-webpack-plugin 打包分析: 修改vue.config.js文件 speed-measure-webpack-plugin进行构建速度分析,需要包裹整个 configureWebpack 配置 const originalConfig {publicPath: /,assetsDir: assets,parallel: true,devS…...

国产化Excel处理组件Spire.XLS教程:如何使用 C# 将 Excel(XLS 或 XLSX)文件转换为 PDF

Excel 是常见的数据处理与呈现工具,但直接共享 Excel 文件可能面临格式错乱、兼容性不足或数据泄露的风险。为了保证文档在不同平台和终端上的稳定展示,开发者常常需要将 Excel 文件转换为 PDF 格式。 本文将详细介绍如何使用 C#和.NET Excel 库——Spi…...

B3623 枚举排列(递归实现排列型枚举)

B3623 枚举排列(递归实现排列型枚举) - 洛谷 题目描述 今有 n 名学生,要从中选出 k 人排成一列拍照。 请按字典序输出所有可能的排列方式。 输入格式 仅一行,两个正整数 n,k。 输出格式 若干行,每行 k 个正整数…...

vue-08(使用slot进行灵活的组件渲染)

使用slot进行灵活的组件渲染 作用域slot是 Vue.js 中的一种强大机制,它允许父组件自定义子组件内容的呈现。与仅向下传递数据的常规 props 不同,作用域 slot 为父级提供了一个模板,然后子级可以填充数据。这提供了高度的灵活性和可重用性&am…...

Fine Pruned Tiled Light Lists(精细删减的分块光照列表)

概括 在这篇文章, 我将介绍一种Tiled Light 变体,主要针对AMD Graphics Core Next(GCN)架构进行优化,我们的方法应用于游戏 古墓丽影:崛起 中,特别是我们在通过光列表生成和阴影贴图渲染之间交错进行异步计…...

2025-5-29-C++ 学习 字符串(3)

字符串 2025-5-29-C 学习 字符串(3)P3741 小果的键盘题目背景题目描述输入格式输出格式输入输出样例 #1输入 #1输出 #1 输入输出样例 #2输入 #2输出 #2 输入输出样例 #3输入 #3输出 #3 输入输出样例 #4输入 #4输出 #4 输入输出样例 #5输入 #5输出 #5 说明…...

openresty+lua+redis把非正常访问的域名加入黑名单

一、验证lua geoIp2是否缺少依赖 1、执行命令 /usr/local/openresty/bin/opm get anjia0532/lua-resty-maxminddb 执行安装命令报错,缺少Digest/MD5依赖 2、Digest/MD5依赖 yum -y install perl-Digest-MD5 GeoIP2 lua库依赖动态库安装,lua库依赖libmaxminddb实…...

使用Mathematica绘制随机多项式的根

使用ListPlot和NSolve直接绘制: (*返回系数为r和s之间整数的n次随机多项式*) eq[n_, r_, s_] : RandomInteger[{r, s}, {n}] . Array[Power[x, # - 1] &, n] (*返回给定随机多项式的根所对应的笛卡尔坐标*) sol[n_, r_, s_] : {Re[#], Im[#]} & / (x /.…...

IEEE PRMVAI 2025 WS 26:计算机视觉前沿 Workshop 来袭!

宝子们,搞计算机视觉和深度学习的看过来啦!🎉 2025 年 IEEE 第三届模式识别、机器视觉和人工智能国际会议里,Workshop 26 简直是科研宝藏地! 这次 Workshop 聚焦 “Deep learning - based low - level models for comp…...

360浏览器设置主题

设置默认主题: 1.右上角有个皮肤按钮 进来后,右边有个回复默认皮肤按钮。 换成彩色皮肤后,找按钮不太好找了。...

最卸载器——Geek Uninstaller 使用指南

Geek Uninstaller 是一款轻量级的第三方卸载工具,专为 Windows 系统设计,提供比系统默认卸载器更彻底的应用清除能力。它体积小、绿色免安装,使用起来简单直观,但功能却不含糊。 一、为什么要用 Geek Uninstaller? Wi…...

leetcode216.组合总和III:回溯算法中多条件约束下的状态管理

一、题目深度解析与组合约束条件 题目描述 找出所有相加之和为n的k个数的组合,且满足以下条件: 每个数只能使用一次(范围为1到9)所有数字均为唯一的正整数组合中的数字按升序排列 例如,当k3,n9时&#…...

应急响应靶机-web3-知攻善防实验室

题目: 1.攻击者的两个IP地址 2.攻击者隐藏用户名称 3.三个攻击者留下的flag 密码:yj123456 解题: 1.攻击者的两个IP地址 一个可能是远程,D盾,404.php,192.168.75.129 找到远程连接相关的英文,1149代表远程连接成功…...

【基于SpringBoot的图书购买系统】Redis中的数据以分页的形式展示:从配置到前后端交互的完整实现

引言 在当今互联网应用开发中,高性能和高并发已经成为系统设计的核心考量因素。Redis作为一款高性能的内存数据库,以其快速的读写速度、丰富的数据结构和灵活的扩展性,成为解决系统缓存、高并发访问等场景的首选技术之一。在图书管理系统中&…...

Jupyter MCP服务器部署实战:AI模型与Python环境无缝集成教程

Jupyter MCP 服务器是基于模型上下文协议(Model Context Protocol, MCP)的 Jupyter 环境扩展组件,它能够实现大型语言模型与实时编码会话的无缝集成。该服务器通过标准化的协议接口,使 AI 模型能够安全地访问和操作 Jupyter 的核心…...

PMO价值重构:从项目管理“交付机器”到“战略推手”

在数字化转型浪潮中,项目管理办公室(PMO)正经历着前所未有的角色蜕变。传统上,PMO往往被视为项目管理的“交付机器”,专注于项目的按时交付和资源分配。然而,随着企业对战略执行的重视,PMO正逐渐…...

如何成为一名优秀的产品经理

一、 夯实核心基础 深入理解智能驾驶技术栈: 感知: 摄像头、雷达(毫米波、激光雷达)、超声波传感器的工作原理、优缺点、融合策略。了解目标检测、跟踪、SLAM等基础算法概念。 定位: GNSS、IMU、高精地图、轮速计等定…...

[SLAM自救笔记0]:开端

📍背景介绍 本人本硕双非,目前研究方向为4D毫米波雷达SLAM与多传感器融合。主攻技术栈是RIO(Radar-Inertial Odometry)与LIO(LiDAR-Inertial Odometry)。 🎯定位方向说明 虽然研究方向偏RIO&…...

零知开源——STM32F407VET6驱动Flappy Bird游戏教程

简介 本教程使用STM32F407VET6零知增强板驱动3.5寸TFT触摸屏实现经典Flappy Bird游戏。通过触摸屏控制小鸟跳跃,躲避障碍物柱体,挑战最高分。项目涉及STM32底层驱动、图形库移植、触摸控制和游戏逻辑设计。 目录 简介 一、硬件准备 二、软件架构 三、…...

[SC]SystemC在CPU和GPU等复杂SoC验证中的应用

SystemC在CPU和GPU等复杂SoC验证中的应用 摘要:SystemC 是一种基于 C++ 的硬件描述和仿真语言,广泛用于系统级设计和验证,特别是在 CPU 和 GPU 等复杂 SoC (System on Chip) 的验证工作中。通过 SystemC,你可以构建硬件模块、定义时序行为、进行系统级仿真,并与 UV…...

鸿蒙OSUniApp导航栏组件开发:打造清新简约的用户界面#三方框架 #Uniapp

UniApp 开发实战:打造符合鸿蒙设计风格的日历活动安排组件 在移动应用开发中,日历和活动安排是非常常见的需求。本文将详细介绍如何使用 UniApp 框架开发一个优雅的日历活动安排组件,并融入鸿蒙系统的设计理念,实现一个既美观又实…...

力扣HOT100之动态规划:300. 最长递增子序列

这道题之前刷代码随想录的时候也刷过,现在又给忘完了。自己尝试着写了一下,发现怎么写都写不对,直接去看视频了。。我自己写的时候的定义是:考虑下标0 ~ i范围内索赔能取到的最长严格递增子序列的长度,后面发现在写递推…...

EEPROM库详解

EEPROM EEPROM 地址空间: 每个字节有唯一地址(从 0 开始),例如 ATmega328P 的地址范围是 0~1023(共 1KB)。不同型号的 Arduino 板 EEPROM 大小不同(如 Mega2560 为 4KB,地址 0~409…...

JDK21深度解密 Day 10:微服务架构适配JDK21

【JDK21深度解密 Day 10】微服务架构适配JDK21 引言:百万并发时代的微服务进化 作为"JDK21深度解密"系列的第10天,今天我们聚焦微服务架构在JDK21时代的技术跃迁。Java语言历史上最大的一次并发模型革新——虚拟线程(Virtual Threads),正在重塑微服务架构的底…...

Java并发编程实战 Day 2:线程安全与synchronized关键字

【Java并发编程实战 Day 2】线程安全与synchronized关键字 开篇 欢迎来到《Java并发编程实战》系列的第二天!在第一天中,我们学习了Java并发编程的基础知识以及线程模型的核心概念。今天我们将继续深入探讨并发编程中的关键问题——线程安全&#xff0…...

在win10/11下Node.js安装配置教程

下载安装 官网链接https://nodejs.org/zh-cn 下载好以后双击打开,点击下一步 勾选,然后下一步 选择路径、下一步 下一步 配置环境 找到我们安装的文件夹,创建两个文件夹 node_global node_cache 在CMD中配置路径 npm config set p…...

飞致云开源社区月度动态报告(2025年5月)

自2023年6月起,中国领先的开源软件公司飞致云以月度为单位发布《飞致云开源社区月度动态报告》,旨在向广大社区用户同步飞致云旗下系列开源软件的发展情况,以及当月主要的产品新版本发布、社区运营成果等相关信息。 飞致云开源运营数据概览&…...

压缩包方式在Linux和Windows下安装mongodb

目录 安装流程安装实例1. Linux安装2. Windows安装 总结 安装流程 zip方式安装 优点:自定义性较高,可以自己控制数据、日志等文件的位置 1、下载安装包 2、解压安装包 3、创建各类文件路径 4、配置conf文件 5、使用自定义配置文件启动 安装实例 1. Li…...

智慧场馆:科技赋能的艺术盛宴

智慧场馆作为城市公共服务设施数字化转型的典型代表,通过深度融合新一代信息技术,构建起全方位、智能化的运营管理体系。其功能架构不仅提升了场馆本身的运营效能,更重塑了公共服务体验模式,展现出显著的社会价值和商业潜力。 一…...

flutter常用动画

Flutter 动画基础概念 术语解释Animation表示动画的值,通常是一个 double (0.0 ~ 1.0) 或其他数值。AnimationController管理动画的时间进度和状态。需要 Ticker (vsync) 来驱动。Tween定义动画的取值范围,如从 0.0 到 1.0,从红色到蓝色。Cu…...