Skip to content

Commit

Permalink
build: storybook-static,still have nuxt inst issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chakAs3 committed Oct 25, 2023
1 parent 8f4da17 commit ac15e16
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
5 changes: 4 additions & 1 deletion packages/storybook-nuxt-cli/src/add-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { existsSync } from 'node:fs'
import fsp from 'node:fs/promises'
import { relative } from 'node:path'
import { cwd } from 'node:process'
import { consola } from 'consola'

// import { consola } from 'consola'
import c from 'picocolors'
import { parseModule } from 'magicast'
import { diffLines } from 'diff'
import path, { join } from 'pathe'

const consola = console

export async function addModuleToNuxtConfigFile(moduleName, cwd) {
const nuxtConfig = findNuxtConfig(cwd)
if (!nuxtConfig) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template>
<NuxtImg src="https://raw.githubusercontent.com/nuxt/nuxt/HEAD/.github/assets/banner.png" />
<NuxtImg src="https://github-production-user-asset-6210df.s3.amazonaws.com/904724/267021354-0396b16c-be9b-4b0d-83b5-5e35dd8298df.png" />
</template>
4 changes: 3 additions & 1 deletion packages/storybook-nuxt/playground/pages/about.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ defineProps({

<template>
<div>
About Storybook Nuxt Playground
About Storybook Nuxt Playground with Nuxt Image
</div>
<div>
{{ msg }}
</div>
Nuxt Image
<MyNuxtImage />
</template>
2 changes: 2 additions & 0 deletions packages/storybook-nuxt/playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ defineProps({
<template>
<div>
Home Storybook
Nuxt Image
<MyNuxtImage />
</div>
<div>
{{ msg }}
Expand Down
6 changes: 4 additions & 2 deletions packages/storybook-nuxt/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ async function extendComposables(nuxt: Nuxt) {

async function defineNuxtConfig(baseConfig: Record<string, any>) {
const { loadNuxt, buildNuxt, addPlugin, extendPages } = await import('@nuxt/kit')

nuxt = await loadNuxt({
rootDir: baseConfig.root,
ready: false,
dev: false,
dev: process.env.NODE_ENV !== 'production',

overrides: {
ssr: false,
},
Expand Down Expand Up @@ -137,7 +139,7 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (
const nuxtConfig = await defineNuxtConfig(await getStorybookViteConfig(config, options))

return mergeConfig(nuxtConfig.viteConfig, {
build: { rollupOptions: { external: ['vue', 'vue-demi'] } },
build: { rollupOptions: { external: process.env.NODE_ENV === 'production' ? [] : ['vue', 'vue-demi'] } },
define: {
__NUXT__: JSON.stringify({ config: nuxtConfig.nuxt.options.runtimeConfig }),
},
Expand Down
8 changes: 3 additions & 5 deletions packages/storybook-nuxt/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import consola from 'consola'

const vueAppRootContainer = document.createElement('div')
vueAppRootContainer.id = '__nuxt'
vueAppRootContainer.setAttribute('hidden', 'true')
Expand All @@ -8,12 +6,12 @@ document.body.appendChild(vueAppRootContainer)
async function nuxtAppEntry() {
const nuxtApp = () => import(('#app/entry')).then(m => m.default).catch(() => {})
// i
const vueAppPromise = nuxtApp().catch((error) => {
consola.error('Error while mounting app:', error)
const vueAppPromise = nuxtApp().catch((_error) => {
// consola.error('Error while mounting app:', error)
})
return vueAppPromise
}

nuxtAppEntry().then((app) => {
consola.info('nuxtAppEntry done', app)
// consola.info('nuxtAppEntry done', app)
})
4 changes: 3 additions & 1 deletion packages/storybook-nuxt/src/runtime/plugins/storybook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createNuxtApp, defineNuxtPlugin } from 'nuxt/app'
import { getContext } from 'unctx'
import logger from 'consola'

// import logger from 'consola'

import type { App } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
Expand All @@ -11,6 +12,7 @@ import plugins from '#build/plugins'
import '#build/css'

const globalWindow = window as any
const logger = console

export default defineNuxtPlugin({
name: 'storybook-nuxt-plugin',
Expand Down

0 comments on commit ac15e16

Please sign in to comment.