Skip to content

Commit

Permalink
feat(vue): remove unknown components warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Feb 5, 2023
1 parent 4bbd939 commit 47517f8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/histoire-plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions packages/histoire/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
6 changes: 6 additions & 0 deletions packages/histoire/src/node/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47517f8

Please sign in to comment.