main.ts 1.5 KB

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