Skip to content

Commit

Permalink
preview refactory
Browse files Browse the repository at this point in the history
  • Loading branch information
chakAs3 committed Sep 28, 2023
1 parent 53aaf3d commit cc97a41
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 317 deletions.
2 changes: 1 addition & 1 deletion packages/storybook-nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook-vue/nuxt",
"version": "0.1.3",
"version": "0.1.4-alpha.0",
"packageManager": "[email protected]",
"description": "Storybook for Nuxt and Vite: Develop Vue3 components in isolation with Hot Reloading.",
"license": "MIT",
Expand Down
52 changes: 3 additions & 49 deletions packages/storybook-nuxt/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
import { applyPlugins, createNuxtApp } from 'nuxt/app'
import { createApp, defineComponent, nextTick } from 'vue'
import consola from 'consola'

import '#build/css'

// @ts-expect-error virtual file
import plugins from '#build/plugins'

// inject nuxt root element
let vueAppPromise: Promise<any>

const RootComponent = defineComponent({
template: '<div></div>',
})

const vueAppRootContainer = document.createElement('div')
vueAppRootContainer.id = '__nuxt'
document.body.appendChild(vueAppRootContainer)

async function initApp() {
if (vueAppPromise)
return vueAppPromise

const vueApp = createApp(RootComponent)

const nuxt = createNuxtApp({ vueApp })

// Define plugins as an array of Plugin type

try {
await applyPlugins(nuxt, plugins)
}
catch (err) {
await nuxt.callHook('app:error', err)
consola.error('Error while applying plugins:', err)
}

try {
await nuxt.hooks.callHook('app:created', vueApp)
await nuxt.hooks.callHook('app:beforeMount', vueApp)
vueApp.mount(vueAppRootContainer)
await nuxt.hooks.callHook('app:mounted', vueApp)
await nextTick()
}
catch (err) {
await nuxt.callHook('app:error', err)
consola.error('Error while mounting app:', err)
// nuxt.payload.error = nuxt.payload.error || err
}

return vueApp
}

async function nuxtAppEntry() {
vueAppPromise = initApp().catch((error) => {
const nuxtApp = () => import(('#app/entry')).then(m => m.default).catch(() => {})
// i
const vueAppPromise = nuxtApp().catch((error) => {
consola.error('Error while mounting app:', error)
})
return vueAppPromise
Expand Down
Loading

0 comments on commit cc97a41

Please sign in to comment.