Skip to content

Commit cc97a41

Browse files
committed
preview refactory
1 parent 53aaf3d commit cc97a41

File tree

3 files changed

+71
-317
lines changed

3 files changed

+71
-317
lines changed

packages/storybook-nuxt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@storybook-vue/nuxt",
3-
"version": "0.1.3",
3+
"version": "0.1.4-alpha.0",
44
"packageManager": "[email protected]",
55
"description": "Storybook for Nuxt and Vite: Develop Vue3 components in isolation with Hot Reloading.",
66
"license": "MIT",

packages/storybook-nuxt/src/preview.ts

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,13 @@
1-
import { applyPlugins, createNuxtApp } from 'nuxt/app'
2-
import { createApp, defineComponent, nextTick } from 'vue'
31
import consola from 'consola'
42

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-
173
const vueAppRootContainer = document.createElement('div')
184
vueAppRootContainer.id = '__nuxt'
195
document.body.appendChild(vueAppRootContainer)
206

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-
557
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) => {
5711
consola.error('Error while mounting app:', error)
5812
})
5913
return vueAppPromise

0 commit comments

Comments
 (0)