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

项目首次渲染,cesium.js过大导致页面加载过慢 #40

Open
tingyuxuan2302 opened this issue Nov 30, 2022 · 5 comments
Open

Comments

@tingyuxuan2302
Copy link

如题,这种大文件首次加载怎么在vite里边处理呢,或者说怎么让它懒加载?

@nshen
Copy link
Owner

nshen commented Nov 30, 2022

我觉得没啥办法,想用他类库就要先加载它吧

@tingyuxuan2302
Copy link
Author

我觉得没啥办法,想用他类库就要先加载它吧

我是在子页面用到的,但这个资源首页就加载了😂

@nshen
Copy link
Owner

nshen commented Dec 1, 2022

哦,应该没有考虑过这个,首页默认会有一个<script src="...cesium"> ,不知道加一个 type="module" 会不会延迟加载?<script type="module" src="..."> 应该不会阻塞首页,你可以先手动改一下试试,如果可以我加到插件里

@SunDawning
Copy link

目前(<2023-02-04 Sat 15:43:33 UTC+08:00>)我是这样操作的来避免首页加载Cesium.js的:

  1. 将首页和子页面都使用动态导入的方式进行懒加载 https://router.vuejs.org/zh/guide/advanced/lazy-loading.html
  2. 设置本插件的rebuildCesium为true并重启vite

但所有页面仍都会加载cesium/Widgets/widgets.css,需求点是让Cesium库只在相应页面加载。

src/main.js:

import { createRouter, createWebHashHistory } from "vue-router";
const Home = function () {
  return import("./Home.vue");
};
const Map = function () {
  return import("./Map.vue");
};
const routes = [
  { path: "/", component: Home },
  { path: "/map", component: Map },
];
const router = createRouter({ history: createWebHashHistory(), routes });
app.use(router);

vite.config.js:

import cesium from "vite-plugin-cesium";
plugins.push(cesium({ rebuildCesium: true }));

@lienahu9
Copy link

大佬,可以写个回调进去吗?在cesiumjs加载完时触发这个回调函数?

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

4 participants