2022-03-22 15:51:26 +00:00
|
|
|
// We set __webpack_public_path via this import with webpack builder
|
2022-02-25 12:42:34 +00:00
|
|
|
import { createSSRApp, createApp, nextTick } from 'vue'
|
2022-04-07 11:28:04 +00:00
|
|
|
import { $fetch } from 'ohmyfetch'
|
2022-04-29 09:38:22 +00:00
|
|
|
// @ts-ignore
|
2022-04-20 12:35:33 +00:00
|
|
|
import { baseURL } from '#build/paths.mjs'
|
2022-02-25 12:42:34 +00:00
|
|
|
import { createNuxtApp, applyPlugins, normalizePlugins, CreateOptions } from '#app'
|
|
|
|
import '#build/css'
|
|
|
|
// @ts-ignore
|
|
|
|
import _plugins from '#build/plugins'
|
|
|
|
// @ts-ignore
|
|
|
|
import RootComponent from '#build/root-component.mjs'
|
|
|
|
// @ts-ignore
|
|
|
|
import AppComponent from '#build/app-component.mjs'
|
2021-05-20 11:42:41 +00:00
|
|
|
|
2022-04-07 11:28:04 +00:00
|
|
|
if (!globalThis.$fetch) {
|
2022-04-29 09:38:22 +00:00
|
|
|
// @ts-ignore
|
2022-04-20 12:35:33 +00:00
|
|
|
globalThis.$fetch = $fetch.create({
|
|
|
|
baseURL: baseURL()
|
|
|
|
})
|
2022-04-07 11:28:04 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 12:42:34 +00:00
|
|
|
let entry: Function
|
|
|
|
|
|
|
|
const plugins = normalizePlugins(_plugins)
|
|
|
|
|
|
|
|
if (process.server) {
|
2022-06-08 19:37:50 +00:00
|
|
|
entry = async function createNuxtAppServer (ssrContext: CreateOptions['ssrContext']) {
|
2022-02-25 12:42:34 +00:00
|
|
|
const vueApp = createApp(RootComponent)
|
|
|
|
vueApp.component('App', AppComponent)
|
|
|
|
|
|
|
|
const nuxt = createNuxtApp({ vueApp, ssrContext })
|
|
|
|
|
2022-03-11 08:22:16 +00:00
|
|
|
try {
|
|
|
|
await applyPlugins(nuxt, plugins)
|
|
|
|
await nuxt.hooks.callHook('app:created', vueApp)
|
|
|
|
} catch (err) {
|
|
|
|
await nuxt.callHook('app:error', err)
|
|
|
|
ssrContext.error = ssrContext.error || err
|
|
|
|
}
|
2022-02-25 12:42:34 +00:00
|
|
|
|
|
|
|
return vueApp
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 11:42:41 +00:00
|
|
|
|
|
|
|
if (process.client) {
|
2022-02-25 12:42:34 +00:00
|
|
|
// TODO: temporary webpack 5 HMR fix
|
|
|
|
// https://github.com/webpack-contrib/webpack-hot-middleware/issues/390
|
|
|
|
// @ts-ignore
|
|
|
|
if (process.dev && import.meta.webpackHot) {
|
|
|
|
// @ts-ignore
|
|
|
|
import.meta.webpackHot.accept()
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = async function initApp () {
|
|
|
|
const isSSR = Boolean(window.__NUXT__?.serverRendered)
|
|
|
|
const vueApp = isSSR ? createSSRApp(RootComponent) : createApp(RootComponent)
|
|
|
|
vueApp.component('App', AppComponent)
|
|
|
|
|
|
|
|
const nuxt = createNuxtApp({ vueApp })
|
|
|
|
|
|
|
|
nuxt.hooks.hookOnce('app:suspense:resolve', () => {
|
|
|
|
nuxt.isHydrating = false
|
|
|
|
})
|
|
|
|
|
2022-03-11 08:22:16 +00:00
|
|
|
try {
|
|
|
|
await applyPlugins(nuxt, plugins)
|
|
|
|
} catch (err) {
|
|
|
|
await nuxt.callHook('app:error', err)
|
|
|
|
nuxt.payload.error = nuxt.payload.error || err
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await nuxt.hooks.callHook('app:created', vueApp)
|
|
|
|
await nuxt.hooks.callHook('app:beforeMount', vueApp)
|
|
|
|
vueApp.mount('#__nuxt')
|
|
|
|
await nuxt.hooks.callHook('app:mounted', vueApp)
|
|
|
|
await nextTick()
|
|
|
|
} catch (err) {
|
|
|
|
await nuxt.callHook('app:error', err)
|
|
|
|
nuxt.payload.error = nuxt.payload.error || err
|
|
|
|
}
|
2022-02-25 12:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entry().catch((error) => {
|
|
|
|
console.error('Error while mounting app:', error) // eslint-disable-line no-console
|
|
|
|
})
|
2021-05-20 11:42:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 12:42:34 +00:00
|
|
|
export default (ctx?: CreateOptions['ssrContext']) => entry(ctx)
|