2021-05-20 11:42:41 +00:00
|
|
|
import { createSSRApp, createApp, nextTick } from 'vue'
|
2021-10-02 18:40:10 +00:00
|
|
|
import { createNuxtApp, applyPlugins, normalizePlugins, CreateOptions } from '#app'
|
2021-08-09 15:42:52 +00:00
|
|
|
import '#build/css'
|
2021-05-20 11:42:41 +00:00
|
|
|
// @ts-ignore
|
2021-06-18 17:16:51 +00:00
|
|
|
import _plugins from '#build/plugins'
|
2021-05-20 11:42:41 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import App from '#build/app'
|
|
|
|
|
|
|
|
let entry: Function
|
|
|
|
|
2021-06-18 17:16:51 +00:00
|
|
|
const plugins = normalizePlugins(_plugins)
|
|
|
|
|
2021-05-20 11:42:41 +00:00
|
|
|
if (process.server) {
|
2021-07-20 10:20:17 +00:00
|
|
|
entry = async function createNuxtAppServer (ssrContext: CreateOptions['ssrContext'] = {}) {
|
2021-05-20 11:42:41 +00:00
|
|
|
const app = createApp(App)
|
|
|
|
|
2021-10-02 18:40:10 +00:00
|
|
|
const nuxt = createNuxtApp({ app, ssrContext })
|
2021-05-20 11:42:41 +00:00
|
|
|
|
|
|
|
await applyPlugins(nuxt, plugins)
|
|
|
|
|
|
|
|
await nuxt.hooks.callHook('app:created', app)
|
|
|
|
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.client) {
|
2021-06-30 16:02:57 +00:00
|
|
|
// TODO: temporary webpack 5 HMR fix
|
|
|
|
// https://github.com/webpack-contrib/webpack-hot-middleware/issues/390
|
2021-07-12 10:19:34 +00:00
|
|
|
// @ts-ignore
|
|
|
|
if (process.dev && import.meta.webpackHot) {
|
2021-07-20 10:20:17 +00:00
|
|
|
// @ts-ignore
|
2021-07-12 10:19:34 +00:00
|
|
|
import.meta.webpackHot.accept()
|
2021-06-30 16:02:57 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 11:42:41 +00:00
|
|
|
entry = async function initApp () {
|
2021-07-21 20:05:22 +00:00
|
|
|
const isSSR = Boolean(window.__NUXT__?.serverRendered)
|
|
|
|
const app = isSSR ? createSSRApp(App) : createApp(App)
|
2021-05-20 11:42:41 +00:00
|
|
|
|
2021-10-02 18:40:10 +00:00
|
|
|
const nuxt = createNuxtApp({ app })
|
2021-05-20 11:42:41 +00:00
|
|
|
|
|
|
|
await applyPlugins(nuxt, plugins)
|
|
|
|
|
|
|
|
await nuxt.hooks.callHook('app:created', app)
|
|
|
|
await nuxt.hooks.callHook('app:beforeMount', app)
|
|
|
|
|
2021-08-26 18:57:36 +00:00
|
|
|
nuxt.hooks.hookOnce('page:finish', () => {
|
2021-07-21 20:06:05 +00:00
|
|
|
nuxt.isHydrating = false
|
|
|
|
})
|
|
|
|
|
2021-05-20 11:42:41 +00:00
|
|
|
app.mount('#__nuxt')
|
|
|
|
|
|
|
|
await nuxt.hooks.callHook('app:mounted', app)
|
|
|
|
await nextTick()
|
|
|
|
}
|
|
|
|
|
|
|
|
entry().catch((error) => {
|
|
|
|
console.error('Error while mounting app:', error) // eslint-disable-line no-console
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-20 10:20:17 +00:00
|
|
|
export default (ctx?: CreateOptions['ssrContext']) => entry(ctx)
|