Skip to content

Commit

Permalink
Merge pull request nuxt-modules#86 from storybook-vue/path-preview
Browse files Browse the repository at this point in the history
fix: vit:vue plugin versions
  • Loading branch information
chakAs3 authored Dec 17, 2023
2 parents 3870636 + 7ad02fc commit c20de2a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 43 deletions.
4 changes: 4 additions & 0 deletions packages/storybook-nuxt/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## v0.2.0

[compare changes](https://github.com/storybook-vue/storybook-nuxt/compare/v0.2.0-alpha.4...v0.2.0)

## v0.1.9

[compare changes](https://github.com/storybook-vue/storybook-nuxt/compare/v0.1.9-alpha.0...v0.1.9)
Expand Down
7 changes: 4 additions & 3 deletions packages/storybook-nuxt/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export default defineBuildConfig({
declaration: true,
entries: [
{ input: 'src/index' },
{ input: 'src/preview' },
{ input: 'src/preset', outDir: 'dist/', format: 'cjs', ext: 'js' },
{ input: 'src/preview', outDir: 'dist/', format: 'esm', ext: 'js' },
{
input: 'src/runtime/', outDir: 'dist/runtime', format: 'esm', ext: 'js',
},
Expand All @@ -18,7 +18,6 @@ export default defineBuildConfig({
},
dependencies: [
'vue-router',
'vue',
'@storybook/vue3',
'@storybook/builder-vite',
'@storybook/vue3-vite',
Expand All @@ -27,13 +26,15 @@ export default defineBuildConfig({
'nuxt',
'nuxt/schema',
'nuxt/app',
'vue',
'@storybook/types',
'@storybook/vue3',
'@vue/shared',
'@unhead/vue',
'@nuxt/devtools-kit',
'#app/composables/state',

'#app/entry',
'#build/plugins',
],
failOnWarn: false,
})
43 changes: 25 additions & 18 deletions packages/storybook-nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@storybook-vue/nuxt",
"version": "0.1.9",
"type": "module",
"version": "0.2.0",
"packageManager": "pnpm@8.6.12",
"description": "Storybook for Nuxt and Vite: Develop Vue3 components in isolation with Hot Reloading.",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +33,6 @@
"./preview": {
"types": "./dist/preview.d.ts",
"import": "./dist/preview.mjs",
"require": "./dist/preview.cjs",
"default": "./preview.js"
},
"./package.json": "./package.json"
Expand All @@ -50,7 +50,7 @@
"*.d.ts"
],
"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},
"scripts": {
"build": "unbuild",
Expand All @@ -61,31 +61,38 @@
"release": "pnpm changelogen --release --push && pnpm publish"
},
"peerDependencies": {
"nuxt": "^3.6 || ^3.7",
"vite": "^4.0.0",
"vue": "^3.3.4"
"nuxt": "^3.6 || ^3.7 || ^3.8",
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0",
"vue": "^3.0.0"
},
"dependencies": {
"@nuxt/devtools-kit": "^0.7.2",
"@nuxt/kit": "3.6.5",
"@nuxt/schema": "3.6.5",
"@nuxt/vite-builder": "3.6.5",
"@storybook/builder-vite": "7.5.1",
"@storybook/vue3": "^7.5.1",
"@storybook/vue3-vite": "^7.5.1",
"@nuxt/devtools-kit": "^1.0.2",
"@nuxt/kit": "3.8.1",
"@nuxt/schema": "3.8.1",
"@nuxt/types": "2.17.2",
"@nuxt/vite-builder": "3.8.1",
"@storybook/builder-vite": "7.5.3",
"@storybook/vue3": "^7.5.3",
"@storybook/vue3-vite": "^7.5.3",
"autoprefixer": "^10.4.15",
"nuxt": "3.8.1",
"postcss": "^8.4.27",
"postcss-import": "^15.1.0",
"postcss-url": "^10.1.3",
"typescript": "^5.2.2",
"vue-router": "^4.2.5"
"typescript": "^5.2.2"
},
"devDependencies": {
"@storybook/types": "7.5.1",
"@storybook/types": "7.5.3",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^3.0.1",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"changelogen": "^0.5.5",
"unbuild": "^2.0.0"
"unbuild": "^2.0.0",
"vite": "4.5.0"
},
"resolutions": {
"@storybook/vue3": "^7.5.3",
"@storybook/vue3-vite": "^7.5.3",
"vite": "4.5.0"
},
"publishConfig": {
"access": "public"
Expand Down
19 changes: 11 additions & 8 deletions packages/storybook-nuxt/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@
"@nuxtjs/color-mode": "^3.3.0",
"@pinia/nuxt": "^0.4.11",
"@storybook-vue/nuxt": "workspace:*",
"@storybook/addon-essentials": "7.5.0-alpha.0",
"@storybook/addon-interactions": "7.5.0-alpha.0",
"@storybook/addon-links": "7.5.0-alpha.0",
"@storybook/blocks": "7.5.0-alpha.0",
"@storybook/addon-essentials": "7.5.3",
"@storybook/addon-interactions": "7.5.3",
"@storybook/addon-links": "7.5.3",
"@storybook/blocks": "7.5.3",
"@storybook/testing-library": "^0.2.0",
"@types/node": "^18.17.5",
"nuxt": "3.6.5",
"nuxt": "3.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "7.5.0-alpha.0",
"storybook": "7.5.3",
"typescript": "^5.1.0",
"vue-router": "4.2.5"
"vue": "^3.3.8",
"vue-router": "^4.2.5"
},
"pnpm": {
"overrides": {
"nuxt": "3.6.5"
"nuxt": "3.8.1",
"vite": "4.5.0",
"vue": "3.3.8"
}
}
}
2 changes: 1 addition & 1 deletion packages/storybook-nuxt/preview.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/preview.mjs'
export * from './dist/preview'
35 changes: 27 additions & 8 deletions packages/storybook-nuxt/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import { createRequire } from 'node:module'
import type { PresetProperty } from '@storybook/types'
import { type UserConfig as ViteConfig, mergeConfig, searchForWorkspaceRoot } from 'vite'
import type { Nuxt } from '@nuxt/schema'
import vuePlugin from '@vitejs/plugin-vue'

import replace from '@rollup/plugin-replace'
import type { StorybookConfig } from './types'
import { pluginsDir } from './dirs'

const packageDir = resolve(fileURLToPath(
import.meta.url), '../..')
const distDir = resolve(fileURLToPath(
import.meta.url), '../..', 'dist')
const runtimeDir = resolve(distDir, 'runtime')
const pluginsDir = resolve(runtimeDir, 'plugins')

const componentsDir = resolve(runtimeDir, 'components')
const composablesDir = resolve(runtimeDir, 'composables')

const dirs = [distDir, packageDir, pluginsDir, componentsDir, composablesDir]
const dirs = [distDir, packageDir, componentsDir, composablesDir, runtimeDir]

let nuxt: Nuxt

Expand Down Expand Up @@ -62,15 +65,17 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
throw new Error(`Storybook-Nuxt does not support '${nuxt.options.builder}' for now.`)

let extendedConfig: ViteConfig = {}
nuxt.options.build.transpile.push(join(packageDir, 'preview'))

nuxt.hook('modules:done', () => {
extendComposables(nuxt)
// Override nuxt-link component to use storybook router
extendComponents(nuxt)
// nuxt.options.build.transpile.push('@storybook-vue/nuxt')
addPlugin({
src: join(pluginsDir, 'storybook'),
mode: 'client',
})
// Override nuxt-link component to use storybook router
extendComponents(nuxt)
// Add iframe page
extendPages((pages: any) => {
pages.push({
Expand All @@ -85,8 +90,13 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
config: ViteConfig | PromiseLike<ViteConfig> | Record<string, any>,
{ isClient }: any,
) => {
if (isClient)
if (isClient) {
const plugins = baseConfig.plugins.filter((plugin: any) => plugin.name !== 'vite:vue')
baseConfig.plugins = [...plugins,
vuePlugin(),
]
extendedConfig = mergeConfig(config, baseConfig)
}
},
)
})
Expand All @@ -96,7 +106,7 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
try {
await buildNuxt(nuxt)

// nuxt.options.dev = true
nuxt.options.dev = true

return {
viteConfig: extendedConfig,
Expand Down Expand Up @@ -139,10 +149,19 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (
const nuxtConfig = await defineNuxtConfig(await getStorybookViteConfig(config, options))

return mergeConfig(nuxtConfig.viteConfig, {
build: { rollupOptions: { external: process.env.NODE_ENV === 'production' ? [] : ['vue', 'vue-demi'] } },
// build: { rollupOptions: { external: ['vue', 'vue-demi'] } },
define: {
__NUXT__: JSON.stringify({ config: nuxtConfig.nuxt.options.runtimeConfig }),
'__NUXT__': JSON.stringify({ config: nuxtConfig.nuxt.options.runtimeConfig }),
'import.meta.client': 'true',
},

plugins: [replace({
values: {
'import.meta.server': 'false',
'import.meta.client': 'true',
},
preventAssignment: true,
})],
server: {
fs: { allow: [searchForWorkspaceRoot(process.cwd()), ...dirs] },
},
Expand Down
14 changes: 11 additions & 3 deletions packages/storybook-nuxt/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ vueAppRootContainer.id = '__nuxt'
vueAppRootContainer.setAttribute('hidden', 'true')
document.body.appendChild(vueAppRootContainer)

// entry()
const logger = console
async function nuxtAppEntry() {
const nuxtApp = () => import(('#app/entry')).then(m => m.default).catch(() => {})
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
}

nuxtAppEntry().then((app) => {
// consola.info('nuxtAppEntry done', app)
nuxtAppEntry().then((app: any) => {
logger.log('nuxtAppEntry done', app)
app().then(() => {
logger.log('nuxtAppEntry app done')
}).catch(() => { logger.log('nuxtAppEntry app error') })
// app()
})

export default nuxtAppEntry
4 changes: 2 additions & 2 deletions packages/storybook-nuxt/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"strict": true,
"paths": {
"#app": [
"/Users/chakir/devs/storybook-nuxt-preset/storybook-nuxt/packages/storybook-nuxt/node_modules/nuxt/dist/app"
"./node_modules/nuxt/dist/app"
],
"#app/entry": [
"/Users/chakir/devs/storybook-nuxt-preset/storybook-nuxt/packages/storybook-nuxt/node_modules/nuxt/dist/app/entry"
"./node_modules/nuxt/dist/app/entry"
]
}
},
Expand Down

0 comments on commit c20de2a

Please sign in to comment.