1
- import { buildNuxt , loadNuxt , tryUseNuxt } from '@nuxt/kit'
2
- import type { StorybookConfig } from '@storybook/vue3-vite'
3
- import { mergeConfig } from 'vite'
1
+ import type { StorybookConfig } from '@storybook-vue/nuxt'
4
2
5
3
const config : StorybookConfig = {
6
4
// Need to specify stories as workaround for https://github.com/storybookjs/storybook/issues/20761
@@ -9,81 +7,10 @@ const config: StorybookConfig = {
9
7
disableTelemetry : true ,
10
8
} ,
11
9
framework : {
12
- name : '@storybook/vue3-vite ' ,
10
+ name : '@storybook-vue/nuxt ' ,
13
11
options : { } ,
14
12
} ,
15
13
addons : [ 'storybook-vue-addon' ] ,
16
- async viteFinal ( config ) {
17
- const nuxtViteConfig = ( await startNuxtAndGetViteConfig ( ) ) . viteConfig
18
- // Need to remove storybook-vue-addon since it will be inserted by the storybook-vue-addon plugin
19
- // TODO: Would be better if we would check there that the plugin is not already added
20
- config . plugins = config . plugins . filter ( ( plugin ) => {
21
- if (
22
- plugin !== null &&
23
- typeof plugin === 'object' &&
24
- 'name' in plugin &&
25
- plugin . name === 'storybook-vue-addon'
26
- ) {
27
- return false
28
- }
29
- return true
30
- } )
31
- return mergeConfig (
32
- {
33
- resolve : nuxtViteConfig . resolve ,
34
- optimizeDeps : nuxtViteConfig . optimizeDeps ,
35
- plugins : nuxtViteConfig . plugins ,
36
- define : nuxtViteConfig . define ,
37
- } ,
38
- config ,
39
- )
40
- } ,
41
- }
42
-
43
- // https://github.com/nuxt/nuxt/issues/14534
44
- // From: https://github.com/danielroe/nuxt-vitest/blob/main/packages/nuxt-vitest/src/config.ts
45
- async function startNuxtAndGetViteConfig ( rootDir = process . cwd ( ) ) {
46
- let nuxt = tryUseNuxt ( )
47
- let nuxtAlreadyRunnnig = true
48
- if ( ! nuxt ) {
49
- nuxtAlreadyRunnnig = false
50
- nuxt = await loadNuxt ( {
51
- cwd : rootDir ,
52
- dev : false ,
53
- overrides : {
54
- ssr : false ,
55
- app : {
56
- rootId : 'nuxt-test' ,
57
- } ,
58
- } ,
59
- } )
60
- }
61
-
62
- const promise = new Promise < { nuxt ; viteConfig } > ( ( resolve , reject ) => {
63
- nuxt . hook ( 'vite:extendConfig' , ( viteConfig , { isClient } ) => {
64
- if ( isClient ) {
65
- resolve ( { nuxt, viteConfig } )
66
- if ( ! nuxtAlreadyRunnnig ) {
67
- throw new Error ( '_stop_' )
68
- }
69
- }
70
- } )
71
-
72
- // TODO: Need better handling if Nuxt is already running
73
- // we don't really want to build nuxt again,
74
- // or at least shutdown the second build after vite:extendConfig is called
75
- buildNuxt ( nuxt ) . catch ( ( err ) => {
76
- if ( ! err . toString ( ) . includes ( '_stop_' ) ) {
77
- reject ( err )
78
- }
79
- } )
80
- } ) . finally ( ( ) => {
81
- if ( ! nuxtAlreadyRunnnig ) {
82
- nuxt . close ( )
83
- }
84
- } )
85
-
86
- return promise
87
14
}
88
15
89
16
export default config
0 commit comments