Vben
2021-04-10 215d8bab380728164d7fe2958c2d2d1151fce892
src/main.ts
@@ -1,30 +1,45 @@
import '/@/design/index.less';
import 'windi.css';
import '@virtual/windi.css';
import { createApp } from 'vue';
import App from './App.vue';
import router, { setupRouter } from '/@/router';
import { setupRouterGuard } from '/@/router/guard';
import { setupStore } from '/@/store';
import { setupErrorHandle } from '/@/logics/error-handle';
import { setupGlobDirectives } from '/@/directives';
import { setupI18n } from '/@/locales/setupI18n';
import { registerGlobComp } from '/@/components/registerGlobComp';
import { isDevMode } from '/@/utils/env';
// Register icon Sprite
import 'vite-plugin-svg-icons/register';
// Do not introduce` on-demand in local development?
// In the local development for on-demand introduction, the number of browser requests will increase by about 20%.
// Which may slow down the browser refresh.
// Therefore, all are introduced in local development, and only introduced on demand in the production environment
if (import.meta.env.DEV) {
  import('ant-design-vue/dist/antd.less');
}
(async () => {
  const app = createApp(App);
  // Configure vuex store
  setupStore(app);
  // Register global components
  registerGlobComp(app);
  // Multilingual configuration
  await setupI18n(app);
  // Configure routing
  setupRouter(app);
  // Configure vuex store
  setupStore(app);
  // router-guard
  setupRouterGuard();
  // Register global directive
  setupGlobDirectives(app);
@@ -32,18 +47,13 @@
  // Configure global error handling
  setupErrorHandle(app);
  await Promise.all([
    // Multilingual configuration
    setupI18n(app),
    // Mount when the route is ready
    router.isReady(),
  ]);
  // Mount when the route is ready
  // https://next.router.vuejs.org/api/#isready
  await router.isReady();
  app.mount('#app', true);
  // The development environment takes effect
  if (isDevMode()) {
    app.config.performance = true;
  if (import.meta.env.DEV) {
    window.__APP__ = app;
  }
})();