Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nuxt vue vite plugin registration fail (fix #590) #643

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/histoire-plugin-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"dependencies": {
"@nuxt/kit": "^3.8.2",
"@rollup/plugin-replace": "^5.0.5",
"@vitejs/plugin-vue": "^4.5.0",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"h3": "^1.9.0",
"ofetch": "^1.3.3",
"unenv": "^1.7.4"
Expand Down
24 changes: 3 additions & 21 deletions packages/histoire-plugin-nuxt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
import vuePlugin from '@vitejs/plugin-vue'
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import replace from '@rollup/plugin-replace'
import type { Plugin } from 'histoire'
import type { Nuxt } from '@nuxt/schema'
Expand All @@ -16,11 +14,6 @@ const ignorePlugins = [
'nuxt:import-protection',
]

const vuePlugins = {
'vite:vue': [vuePlugin, 'vue'],
'vite:vue-jsx': [viteJsxPlugin, 'vueJsx'],
} as const

export function HstNuxt (): Plugin {
let nuxt: Nuxt
return {
Expand Down Expand Up @@ -173,21 +166,10 @@ async function useNuxtViteConfig () {
})
}
})
nuxt.hook('vite:extendConfig', (config, { isClient }) => {
if (isClient) {
const plugins = []

for (const name in vuePlugins) {
if (!config.plugins?.some(p => (p as any)?.name === name)) {
const [plugin, key] = vuePlugins[name as keyof typeof vuePlugins]
plugins.push(plugin(config[key] as any))
}
}

resolve({
...config,
plugins: [...config.plugins, ...plugins],
})
nuxt.hook('vite:configResolved', (config, { isClient }) => {
if (isClient) {
resolve(config)
}
})
})
Expand Down
Loading
Loading