当前位置:网站首页>The slow loading of the first entry page of vite local operation
The slow loading of the first entry page of vite local operation
2022-07-26 01:58:00 【HHH 917】
reflection
vite What is the applicable scenario of ?
Because I used tailwindcss plug-in unit Use webpack Start all projects every time css Styles are pre used tailwindcss convert to css Ordinary computer startup projects need 1 Minutes to 2 minute . However, the first load will not have much delay , There won't be much delay in loading pages imported on demand , but webpack Running down tailwindcss There is a problem that after modifying the style and dynamically compiling and running Check the style too laggy Modify the style for a long time Eat plenty of memory Running for a long time will burst the memory .
Now? vue3 Very popular vite pack , So I also try to use vite.webpack Switch to vite, If you just look at the operation in the command line , Less than a second after running , But the first time you open the page, you need to wait 10 Seconds to 20 Processing time of about seconds The number of requests has reached 132 individual ( Browsers will block such concurrent requests ), The largest file here is also tailwindcss, And open the page route loaded on demand , It still needs to go through tailwindcss compile css, It will take a few seconds to open an unopened page , This experience is very bad .


vite prepackaged
because vite Need to dynamically resolve dependencies , And then pack it . principle Reference resources vite Rely on pre build . So open the page for the first time analysis Packing will be slow , because vite Default dependency build Not as expected The official provided Rely on optimization options Let developers add dependencies optimizeDeps.exclude Or exclude dependencies optimizeDeps.include Here we use optimizeDeps.include Add dependency .
Add dependency
Usually some common dependencies such as vue axios vue-router We all know that we can add dependencies . But some styles js We cannot accurately know the dependencies of the file . Use third-party plug-ins here vite-plugin-optimize-persist
To get dependencies
Reference resources article vite Slow loading when opening the interface for the first time / solve
install plug-in unit
npm i -D vite-plugin-optimize-persist vite-plugin-package-config
vite.config.ts Add the configuration among include There are the dependencies that need to be added
// Automatic generation prepackaged
import OptimizationPersist from "vite-plugin-optimize-persist";
import PkgConfig from "vite-plugin-package-config";
export default ({
mode }) => {
plugins: [
vue(),
// Automatic generation prepackaged
PkgConfig(),
OptimizationPersist(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
optimizeDeps: {
include: [
"element-plus/es",
"element-plus/es/components/config-provider/style/css",
"element-plus/es/components/container/style/css",
"element-plus/es/components/main/style/css",
"element-plus/es/components/header/style/css",
"element-plus/es/components/date-picker/style/css",
"element-plus/es/components/drawer/style/css",
"element-plus/es/components/image/style/css",
"element-plus/es/components/image/style/css",
"element-plus/es/components/table/style/css",
"element-plus/es/components/table-column/style/css",
"element-plus/es/components/input/style/css",
"element-plus/es/components/dropdown/style/css",
"element-plus/es/components/popover/style/css",
"element-plus/es/components/dropdown-item/style/css",
"element-plus/es/components/dropdown-menu/style/css",
"element-plus/es/components/pagination/style/css",
"element-plus/es/components/scrollbar/style/css",
"element-plus/es/components/dialog/style/css",
"element-plus/es/components/loading/style/css",
"element-plus/es/components/tabs/style/css",
"element-plus/es/components/tab-pane/style/css",
"element-plus/es/components/select/style/css",
"element-plus/es/components/option/style/css",
"vue",
"pinia",
"jquery",
"sass",
"vue-router",
// "tailwindcss",
"tailwindcss/plugin",
],
},
}
The original plug-in should be in package.json Automatically generate Be similar to “vite”: {
“optimizeDeps”: {
“include”: [
// managed by vite-plugin-optimize-persist
“@material-ui/core/Accordion”,
“@material-ui/core/AccordionSummary”,
“@material-ui/core/Dialog”,
“@material-ui/core/DialogActions”,
“@material-ui/icons/Dehaze”,
“date-fns/format”,
“lodash/debounce”,
“lodash/map”
]
}
}
Of the dependency of . But I opened the page and found package.json Dependencies are not automatically generated .
So I manually vite.config.ts Add dependency When you first open a page , When ’‘include’' When the array in does not contain the dependency The command line will prompt Just add in .
// Dependency command line prompt 
After adding dependencies It takes hundreds of milliseconds for the command line to finish running But the loading speed of loading pages on demand can be improved
边栏推荐
- 3、 Pinda general permission system__ pd-tools-swagger2
- How uxdb works on multiple processors
- Digital transformation behind the reshaping growth of catering chain stores
- The e-commerce project is written in the resume. How to answer it during the interview
- win下搭建嵌入式开发环境及frp穿透
- Huawei wireless device WDS configuration command
- 重发布基础与配置
- How to use the pagoda panel to deploy the full stack project of node to the server
- Overview of database stress testing methods
- IP address of the network
猜你喜欢

QT program beautification of the use of style sheets, QT uses pictures as the background and transparency of controls, QT custom button styles

Worthington papain - production of glycopeptides from purified proteoglycans (attached Literature)

Typora expiration solution, what if typora can't open

Cross Site Request Forgery (CSRF): impact, examples, and Prevention

How to display numbers / English time in Excel

Worthington核酸酶、微球菌相关研究及测定方案

# Dest0g3 520迎新赛(更新中)
![[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!](/img/52/8c1520db38ffa8927e975b6f244a65.png)
[independent station construction] Shopify seller: learn these points and double the sales volume of online stores!

3、 Pinda general permission system__ pd-tools-swagger2

餐饮连锁门店重塑增长背后的数字化转型
随机推荐
Redis6.x配置参数详解
G2. passable paths (hard version) (tree diameter + LCA)
How to do Taobao live broadcast and how to do the anchor to drain and sell products
图像批处理高斯滤波降噪+峰值信噪比计算
Go operation excel library excel use
npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t
leetcode/只出现一次的数字
Phoenix中常用shell操作
The e-commerce project is written in the resume. How to answer it during the interview
Relationship between HTC mobile official solution, s-on/s-off and super CID
opengauss如何手工安装(非OM方式)
[Verilog digital system design (Xia Yuwen) 4 ----- basic concepts of Verilog syntax 2]
E. OpenStreetMap (2D monotone queue)
Characteristics and determination of neuraminidase from Clostridium perfringens in Worthington
vite 本地运行首次进入页面加载慢问题
There is no setter method in grpc list under flutter. How to use related attributes
SQLyog数据导入导出图文教程
Composition API的优势
DialogRPT-Dialog Ranking Pretrained Transformers
npm ERR! code ETIMEDOUTnpm ERR! syscall connectnpm ERR! errno ETIMEDOUTnpm ERR! network request t