Skip to content

Commit

Permalink
fix: config dev port (fix #317) (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoattal committed Oct 8, 2022
1 parent efcf98b commit 095d516
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/histoire/src/node/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function devCommand (options: DevOptions) {
const ctx = await createContext({
mode: 'dev',
})
const { server, close } = await createServer(ctx, options.port ?? 6006)
const { server, close } = await createServer(ctx, { port: options.port })
server.printUrls()

// Histoire config watcher
Expand Down
8 changes: 6 additions & 2 deletions packages/histoire/src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { useModuleLoader } from './load.js'
import { wrapLogError } from './util/log.js'
import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js'

export async function createServer (ctx: Context, port: number) {
export interface CreateServerOptions {
port?: number
}

export async function createServer (ctx: Context, options: CreateServerOptions = {}) {
const server = await createViteServer(await getViteConfigWithPlugins(false, ctx))
await server.pluginContainer.buildStart({})

Expand All @@ -36,7 +40,7 @@ export async function createServer (ctx: Context, port: number) {
}

// Wait for pre-bundling (in `listen()`)
await server.listen(port)
await server.listen(options.port ?? server.config.server?.port)

const {
clearCache,
Expand Down
5 changes: 3 additions & 2 deletions packages/histoire/src/node/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ async function mergeHistoireViteConfig (viteConfig: InlineConfig, ctx: Context)
export async function getViteConfigWithPlugins (isServer: boolean, ctx: Context): Promise<InlineConfig> {
const resolvedViteConfig = await resolveViteConfig(ctx)

const userViteConfig = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode })
const userViteConfigFile = await loadViteConfigFromFile({ command: ctx.mode === 'dev' ? 'serve' : 'build', mode: ctx.mode })
const userViteConfig = mergeViteConfig(userViteConfigFile?.config ?? {}, { server: { port: 6006 } })

const inlineConfig = await mergeHistoireViteConfig(userViteConfig?.config ?? {}, ctx)
const inlineConfig = await mergeHistoireViteConfig(userViteConfig, ctx)
const plugins: VitePlugin[] = []

const hasPnpm = !!(await findUp(ctx.root, ['pnpm-lock.yaml']))
Expand Down

0 comments on commit 095d516

Please sign in to comment.