Closed deng-yc closed 1 year ago
由于依赖预构建是从项目entry处扫描源码收集第三方库依赖信息后,基于这部分信息对第三方库进行预构建,构建过程中会对关联到的第三方库模块文件基于es-module-lexer进行文件解析(拿到export、import)再往深层次模块文件构建打包,期间由于需要保证构建产物功能的全面,暂时无法进行预构建期间的TreeShaking
经验证,确实由于在预构建@ant-design/icons第三方库时,对es/icons进行了全引入构建,esbuild的build-api耗时较高,最终导致bundle时间较长,对于此目前解决方案是采用alias直接指定viteDevServer可识别的产物路径(path含node_modules)以绕过@ant-design/icons包全亮预构建流程,当访问到的页面加载到与之相关的组件时,Vite会进行加载
Same issues.
Temporary fixed it by set path alias for antd
and antd icons
.
If use reset.css
of antd, have to adjust the alias like this:
// main.jsx
import 'antd/dist/reset.css'
// vite.config.js
resolve: {
alias: {
// ...
'antd/dist/reset.css': path.join(__dirname, 'node_modules/antd/dist/reset.css'), // <-- add this
antd: path.join(__dirname, 'node_modules/antd/dist/antd.js'),
'@ant-design/icons': path.join(__dirname,'node_modules/@ant-design/icons/dist/index.umd.js'),
},
}
Tested with 4.3.0-beta.3 and the performance issue is now solved. Check out the changelog for perf PRs that got us to this result.
I have been troubled for a long time and finally found a solution here. After I introduced @vicons into the vue project, every time I rebuild the package, the first time I start the project, the screen will be white for more than ten minutes. Upgrading to the latest version was solved
Thank you very much for releasing vite v4.3.1
. It has improved the speed significantly.
Tested on the same development project on Windows 10.
System:
OS: Windows 10
CPU: AMD Ryzen 5 3600 6-Core Processor 3.59 GHz
Memory: 16.0 GB
Browsers:
Chrome: 112.0.5615.138 (64bit)
Binaries:
Node: 18.14.0
pnpm: 8.3.1
run command.
$ pnpm vite --force
The time it takes until the page is displayed. (with antd v5.2.1)
Cost | |
---|---|
Vite v4.1.0 | 67 sec |
Vite v4.3.1 | 2.5 sec |
Describe the bug
使用 antd以及@antd-design/icons 首次启动非常慢,大概5分钟以上
Reproduction
https://github.com/deng-yc/vite-antd
Steps to reproduce
重现步骤
影响速度的地方应该是预编译依赖包
可以通过以下代码临时解决在开发时慢
System Info
Used Package Manager
pnpm
Logs
No response
Validations