Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一次npm run dev 后 访问很慢 #383

Open
wing520234 opened this issue Apr 24, 2024 · 9 comments
Open

第一次npm run dev 后 访问很慢 #383

wing520234 opened this issue Apr 24, 2024 · 9 comments

Comments

@wing520234
Copy link

好未加载过的页面访问都特别慢,加载过的页面 就流畅多了

@Gtixlb
Copy link

Gtixlb commented Apr 29, 2024

我也是,抓狂,有没有什么解决方法呢

@jocongmin
Copy link

我也是,代码肯定有问题,这么基本的问题都没解决

@zhang180031
Copy link

项目用的是yarn吧

@excavate
Copy link

我也是,不懂怎么解决

@jocongmin
Copy link

jocongmin commented Jul 12, 2024 via email

@sayid760
Copy link

sayid760 commented Jul 12, 2024 via email

@rick-liruixin
Copy link

rick-liruixin commented Nov 1, 2024

English:

1, Execute npm uninstall unplugin-auto-import unplugin-vue-components
2, Delete these lines of code in the vite.config.ts file:

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

AutoImport({
	resolvers: [ElementPlusResolver()]
}),
Components({
	resolvers: [ElementPlusResolver()]
})

3, Globally import ElementPlus in main.ts, or manually import ElementPlus on a per-file basis.
Example: main.ts

import ElementPlus from "element-plus";

const app = createApp(App);
app.use(createPinia());
app.use(ElementPlus);

When there is no cache, the Components plugin's automatic imports will generate compiled dependencies for the corresponding components in the node_modules/.vite directory, which can be time-consuming due to the creation of new dependencies. The packaged output of Element Plus already has different types of packages and does not need to be recompiled to produce new artifacts.

中文

1, 执行 npm uninstall unplugin-auto-import unplugin-vue-components
2, 删除 vite.config.ts 文件中这几行代码。

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

AutoImport({
	resolvers: [ElementPlusResolver()]
}),
Components({
	resolvers: [ElementPlusResolver()]
})

3, main.ts全局引入ElementPlus 或 自己在文件中手动按需引入ElementPlus。
例:main.ts

import ElementPlus from "element-plus";

const app = createApp(App);
app.use(createPinia());
app.use(ElementPlus);

因为当没有缓存的时候,Components插件自动引入会在node_modules/.vite 目录下产生对应组件编译后的依赖,产生新的依赖特别耗时。element-plus打包后的产物原本就有不同类型的包,不需要再次编译产生新的产物。

我自己的理解。

@excavate @Gtixlb @wing520234 @jocongmin @sayid760

@jocongmin
Copy link

jocongmin commented Nov 1, 2024 via email

@sayid760
Copy link

sayid760 commented Nov 1, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants