diff --git a/packages/histoire-plugin-vue/src/index.ts b/packages/histoire-plugin-vue/src/index.ts index 075d40e4..1cbfe71d 100644 --- a/packages/histoire-plugin-vue/src/index.ts +++ b/packages/histoire-plugin-vue/src/index.ts @@ -18,6 +18,25 @@ export function HstVue (): Plugin { } }, + config () { + return { + vite: { + plugins: [ + { + name: 'histoire-plugin-vue', + enforce: 'post', + transform (code, id) { + // Remove vue warnings about unknown components + if (this.meta.histoire.isCollecting && id.endsWith('.vue')) { + return `const _stubComponent = (name) => ['Story','Variant'].includes(name) ? _resolveComponent(name) : ({ render: () => null });${code.replaceAll('_resolveComponent(', '_stubComponent(')}` + } + } + } + ] + } + } + }, + supportPlugin: { id: 'vue3', moduleName: '@histoire/plugin-vue', diff --git a/packages/histoire/src/node/index.ts b/packages/histoire/src/node/index.ts index c99fa24f..18118030 100644 --- a/packages/histoire/src/node/index.ts +++ b/packages/histoire/src/node/index.ts @@ -2,3 +2,11 @@ export * from '@histoire/shared' export * from './config.js' export * from './plugin.js' export { defaultColors } from './colors.js' + +declare module 'rollup' { + interface PluginContextMeta { + histoire: { + isCollecting: boolean + } + } +} diff --git a/packages/histoire/src/node/vite.ts b/packages/histoire/src/node/vite.ts index 45bb8e06..1188e1c7 100644 --- a/packages/histoire/src/node/vite.ts +++ b/packages/histoire/src/node/vite.ts @@ -196,6 +196,12 @@ export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context) } }, + options () { + this.meta.histoire = { + isCollecting: isServer, + } + }, + async resolveId (id, importer) { if (id.startsWith(STORIES_ID)) { return RESOLVED_STORIES_ID