Skip to content

Commit

Permalink
revert to 0.2.1 with routing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chakAs3 committed Mar 16, 2024
1 parent 4381dfe commit 8ea0b42
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/storybook-nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@storybook-vue/nuxt",
"type": "module",
"version": "0.2.1",
"version": "0.2.3",
"packageManager": "[email protected]",
"description": "Storybook for Nuxt and Vite: Develop Vue3 components in isolation with Hot Reloading.",
"license": "MIT",
Expand Down
50 changes: 36 additions & 14 deletions packages/storybook-nuxt/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { join, resolve } from 'node:path'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
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'
import { componentsDir, composablesDir, pluginsDir, runtimeDir } from './dirs'

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

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

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

let nuxt: Nuxt

Expand Down Expand Up @@ -90,11 +88,21 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
{ isClient }: any,
) => {
if (isClient) {
const plugins = baseConfig.plugins.filter((plugin: any) => plugin.name !== 'vite:vue')
baseConfig.plugins = [
vuePlugin(),
...plugins,
]
const plugins = baseConfig.plugins

// Find the index of the plugin with name 'vite:vue'
const index = plugins.findIndex((plugin: any) => plugin.name === 'vite:vue')

// Check if the plugin was found
if (index !== -1) {
// Replace the plugin with the new one using vuePlugin()
plugins[index] = vuePlugin()
}
else {
// Handle the case where the plugin with name 'vite:vue' was not found
console.error('Plugin \'vite:vue\' not found in the array.')
}
baseConfig.plugins = plugins
extendedConfig = mergeConfig(config, baseConfig)
}
},
Expand All @@ -106,8 +114,6 @@ async function defineNuxtConfig(baseConfig: Record<string, any>) {
try {
await buildNuxt(nuxt)

nuxt.options.dev = true

return {
viteConfig: extendedConfig,
nuxt,
Expand Down Expand Up @@ -173,6 +179,22 @@ export const viteFinal: StorybookConfig['viteFinal'] = async (
envPrefix: ['NUXT_'],
})
}

async function getPackageDir(frameworkPackageName: any) {
// const packageJsonPath = join(frameworkPackageName, 'package.json')

try {
const require = createRequire(import.meta.url)
const packageDir = dirname(require.resolve(join(frameworkPackageName, 'package.json'), { paths: [process.cwd()] }))

return packageDir
}
catch (e) {
// logger.error(e)
}
throw new Error(`Cannot find ${frameworkPackageName},`)
}

export function getNuxtProxyConfig(nuxt: Nuxt) {
const port = nuxt.options.runtimeConfig.app.port ?? 3000
const route = '^/(_nuxt|_ipx|_icon|__nuxt_devtools__)'
Expand Down

0 comments on commit 8ea0b42

Please sign in to comment.