Skip to content

Commit

Permalink
feat(config): vite as function to mutate config
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Mar 9, 2022
1 parent f925bc3 commit d39ca90
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions packages/histoire-controls/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
},
},

Expand Down
4 changes: 2 additions & 2 deletions packages/histoire/src/node/config.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -123,7 +123,7 @@ export interface HistoireConfig {
/**
* Vite config override
*/
vite?: ViteConfig
vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
}

export function getDefaultConfig (): HistoireConfig {
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function createVitePlugins (ctx: Context): Promise<VitePlugin[]> {
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
},
})
}
Expand Down

0 comments on commit d39ca90

Please sign in to comment.