main.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { initPreferences } from '@velofex/preferences';
  2. import { unmountGlobalLoading } from '@velofex/utils';
  3. import { overridesPreferences } from './preferences';
  4. import { mountWindowBridge } from './utils/window-bridge';
  5. function mountLegacyIconStyles() {
  6. if (typeof document === 'undefined') {
  7. return;
  8. }
  9. const styleId = 'webb-legacy-icon-style';
  10. const iconBase = import.meta.env.PROD ? '' : 'https://edesign.shalu.com';
  11. const href = `${iconBase}/Content/Lib/component/icons/icon.css?v=2.2.0`;
  12. const existing = document.querySelector<HTMLLinkElement>(`#${styleId}`);
  13. if (existing) {
  14. existing.href = href;
  15. return;
  16. }
  17. const link = document.createElement('link');
  18. link.id = styleId;
  19. link.rel = 'stylesheet';
  20. link.href = href;
  21. document.head.append(link);
  22. }
  23. /**
  24. * 应用初始化完成之后再进行页面加载渲染
  25. */
  26. async function initApplication() {
  27. mountLegacyIconStyles();
  28. mountWindowBridge();
  29. // name用于指定项目唯一标识
  30. // 用于区分不同项目的偏好设置以及存储数据的key前缀以及其他一些需要隔离的数据
  31. const env = import.meta.env.PROD ? 'prod' : 'dev';
  32. const appVersion = import.meta.env.VITE_APP_VERSION;
  33. const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${appVersion}-${env}`;
  34. // app偏好设置初始化
  35. await initPreferences({
  36. namespace,
  37. overrides: overridesPreferences,
  38. });
  39. // 启动应用并挂载
  40. // vue应用主要逻辑及视图
  41. const { bootstrap } = await import('./bootstrap');
  42. await bootstrap(namespace);
  43. // 移除并销毁loading
  44. unmountGlobalLoading();
  45. }
  46. initApplication();