Skip to content

Commit

Permalink
feat: inline config
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Feb 4, 2025
1 parent c834ab0 commit 175c538
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-baboons-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kopflos-cms/vite": patch
---

Add inline `config` to plugin config
5 changes: 5 additions & 0 deletions example/kopflos.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export default <KopflosConfig> {
'@kopflos-cms/vite': {
root: 'ui',
entrypoints: ['ui/*.html'],
config: {
server: {
allowedHosts: ['read-the-plaque.lndo.site'],
},
},
},
'@kopflos-cms/hydra': {
apis: [baseIri + '/api'],
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { resolve } from 'node:path'
import type { Kopflos, KopflosEnvironment, KopflosPlugin, KopflosPluginConstructor } from '@kopflos-cms/core'
import express from 'express'
import type { InlineConfig } from 'vite'
import { build } from 'vite'
import { createViteServer } from './lib/server.js'
import { prepareConfig } from './lib/config.js'
Expand All @@ -10,6 +11,7 @@ export { defineConfig } from 'vite'

export interface Options {
configPath?: string
config?: InlineConfig
root?: string
outDir?: string
entrypoints?: string[]
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { mergeConfig } from 'vite'
import defaultConfig from '../vite.config.js'
import type { Options } from '../index.js'

export async function prepareConfig({ root, configPath, entrypoints, outDir }: Omit<Options, 'mode'>) {
export async function prepareConfig({ root, configPath, entrypoints, outDir, config = {} }: Omit<Options, 'mode'>) {
const inputConfig: InlineConfig = {
root,
build: {
Expand All @@ -26,5 +26,5 @@ export async function prepareConfig({ root, configPath, entrypoints, outDir }: O
return mergeConfig(mergeConfig(defaultConfig, inputConfig), userConfig.default)
}

return mergeConfig(defaultConfig, inputConfig)
return mergeConfig(config, mergeConfig(defaultConfig, inputConfig))
}

0 comments on commit 175c538

Please sign in to comment.