Skip to content

Commit

Permalink
feat(config): viteIgnorePlugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Aug 23, 2022
1 parent fc10cd8 commit f5ac175
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ export default defineConfig({
})
```

## `viteIgnorePlugins`

`string[]`

List of Vite plugin names to exclude for Histoire.

```ts
export default defineConfig({
viteIgnorePlugins: [
'vite-plugin-svelte-kit',
],
})
```

## `viteNodeTransformMode`

`{ web?, ssr? }`
Expand Down
4 changes: 4 additions & 0 deletions packages/histoire-shared/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export interface HistoireConfig {
* Vite config override
*/
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
/**
* Remove those plugins from the Vite configuration
*/
viteIgnorePlugins?: string[]
/**
* Transpile dependencies when collecting stories on Node.js
*/
Expand Down
1 change: 1 addition & 0 deletions packages/histoire/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function getDefaultConfig (): HistoireConfig {
},
}
},
viteIgnorePlugins: [],
}
}

Expand Down
19 changes: 19 additions & 0 deletions packages/histoire/src/node/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Context)
viteConfig = mergeViteConfig(viteConfig, overrides)
}
}

let flatPlugins = []
if (viteConfig.plugins) {
for (const pluginOption of viteConfig.plugins) {
if (Array.isArray(pluginOption)) {
flatPlugins.push(...await Promise.all(pluginOption))
} else {
flatPlugins.push(await pluginOption)
}
}
flatPlugins = flatPlugins.filter(Boolean)
}

if (ctx.config.viteIgnorePlugins) {
flatPlugins = flatPlugins.filter(plugin => !ctx.config.viteIgnorePlugins.includes(plugin.name))
}

viteConfig.plugins = flatPlugins

return viteConfig
}

Expand Down

0 comments on commit f5ac175

Please sign in to comment.