Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config dev port (fix #317) #318

Merged
merged 4 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } })
Akryum marked this conversation as resolved.
Show resolved Hide resolved

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