From d39ca90599a51e07db36fe9d91301ebe518ce00b Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Thu, 10 Mar 2022 00:57:14 +0100 Subject: [PATCH] feat(config): vite as function to mutate config --- packages/histoire-controls/vite.config.ts | 10 +++------- packages/histoire/src/node/config.ts | 4 ++-- packages/histoire/src/node/plugin.ts | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/histoire-controls/vite.config.ts b/packages/histoire-controls/vite.config.ts index 948bd815..6b1356f0 100644 --- a/packages/histoire-controls/vite.config.ts +++ b/packages/histoire-controls/vite.config.ts @@ -26,13 +26,9 @@ export default defineConfig({ histoire: { setupFile: '/src/histoire-setup.ts', - vite: { - build: { - lib: false, - rollupOptions: { - external: [], - }, - }, + vite: (config) => { + config.build.lib = false + config.build.rollupOptions.external = [] }, }, diff --git a/packages/histoire/src/node/config.ts b/packages/histoire/src/node/config.ts index 39b18c79..f7472e01 100644 --- a/packages/histoire/src/node/config.ts +++ b/packages/histoire/src/node/config.ts @@ -1,7 +1,7 @@ import path from 'pathe' import fs from 'fs' import defu from 'defu' -import { createServer, resolveConfig as resolveViteConfig, UserConfig as ViteConfig } from 'vite' +import { createServer, resolveConfig as resolveViteConfig, UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite' import { ViteNodeServer } from 'vite-node/server' import { ViteNodeRunner } from 'vite-node/client' import pc from 'picocolors' @@ -123,7 +123,7 @@ export interface HistoireConfig { /** * Vite config override */ - vite?: ViteConfig + vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise) } export function getDefaultConfig (): HistoireConfig { diff --git a/packages/histoire/src/node/plugin.ts b/packages/histoire/src/node/plugin.ts index 2b13dd92..ef448ec7 100644 --- a/packages/histoire/src/node/plugin.ts +++ b/packages/histoire/src/node/plugin.ts @@ -30,8 +30,8 @@ export async function createVitePlugins (ctx: Context): Promise { if (ctx.config.vite) { plugins.push({ name: 'histoire-vite-config-override', - config () { - return ctx.config.vite + config (config, env) { + return typeof ctx.config.vite === 'function' ? ctx.config.vite(config, env) : ctx.config.vite }, }) }