|
1 | | -import { applyPlugins, createNuxtApp } from 'nuxt/app' |
2 | | -import { createApp, defineComponent, nextTick } from 'vue' |
3 | 1 | import consola from 'consola' |
4 | 2 |
|
5 | | -import '#build/css' |
6 | | - |
7 | | -// @ts-expect-error virtual file |
8 | | -import plugins from '#build/plugins' |
9 | | - |
10 | | -// inject nuxt root element |
11 | | -let vueAppPromise: Promise<any> |
12 | | - |
13 | | -const RootComponent = defineComponent({ |
14 | | - template: '<div></div>', |
15 | | -}) |
16 | | - |
17 | 3 | const vueAppRootContainer = document.createElement('div') |
18 | 4 | vueAppRootContainer.id = '__nuxt' |
19 | 5 | document.body.appendChild(vueAppRootContainer) |
20 | 6 |
|
21 | | -async function initApp() { |
22 | | - if (vueAppPromise) |
23 | | - return vueAppPromise |
24 | | - |
25 | | - const vueApp = createApp(RootComponent) |
26 | | - |
27 | | - const nuxt = createNuxtApp({ vueApp }) |
28 | | - |
29 | | - // Define plugins as an array of Plugin type |
30 | | - |
31 | | - try { |
32 | | - await applyPlugins(nuxt, plugins) |
33 | | - } |
34 | | - catch (err) { |
35 | | - await nuxt.callHook('app:error', err) |
36 | | - consola.error('Error while applying plugins:', err) |
37 | | - } |
38 | | - |
39 | | - try { |
40 | | - await nuxt.hooks.callHook('app:created', vueApp) |
41 | | - await nuxt.hooks.callHook('app:beforeMount', vueApp) |
42 | | - vueApp.mount(vueAppRootContainer) |
43 | | - await nuxt.hooks.callHook('app:mounted', vueApp) |
44 | | - await nextTick() |
45 | | - } |
46 | | - catch (err) { |
47 | | - await nuxt.callHook('app:error', err) |
48 | | - consola.error('Error while mounting app:', err) |
49 | | - // nuxt.payload.error = nuxt.payload.error || err |
50 | | - } |
51 | | - |
52 | | - return vueApp |
53 | | -} |
54 | | - |
55 | 7 | async function nuxtAppEntry() { |
56 | | - vueAppPromise = initApp().catch((error) => { |
| 8 | + const nuxtApp = () => import(('#app/entry')).then(m => m.default).catch(() => {}) |
| 9 | + // i |
| 10 | + const vueAppPromise = nuxtApp().catch((error) => { |
57 | 11 | consola.error('Error while mounting app:', error) |
58 | 12 | }) |
59 | 13 | return vueAppPromise |
|
0 commit comments