Skip to content

Commit

Permalink
feat: add host config to histoire dev
Browse files Browse the repository at this point in the history
  • Loading branch information
croatialu committed Jul 11, 2024
1 parent 3814da9 commit 1bdedeb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"dev:hst": "nodemon --watch ../../packages/histoire/dist --watch ../../packages/histoire-plugin-vue/dist --exec \"rm -rf ./node_modules/.hst* && HISTOIRE_DEV=true histoire dev\"",
"story:dev": "histoire dev",
"story:dev": "histoire dev --host",
"story:build": "histoire build",
"story:preview": "histoire preview --port 4567",
"ci": "start-server-and-test story:preview http://localhost:4567/ test",
Expand Down
1 change: 1 addition & 0 deletions packages/histoire/src/node/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ program.command('dev')
.option('-p, --port <port>', 'Listening port of the server')
.option('-c, --config <file>', `[string] use specified config file`)
.option('--open', 'Open in your default browser')
.option('--host <host>', '[string] specify hostname')
.action(async (options) => {
const { devCommand } = await import('./commands/dev.js')
return devCommand(options)
Expand Down
2 changes: 2 additions & 0 deletions packages/histoire/src/node/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createServer } from '../server.js'
export interface DevOptions {
port: number
open?: boolean
host?: string | boolean
config?: string
}

Expand All @@ -21,6 +22,7 @@ export async function devCommand(options: DevOptions) {
const { server, viteConfigFile, close } = await createServer(ctx, {
port: options.port,
open: options.open,
host: options.host,
})
server.printUrls()

Expand Down
11 changes: 9 additions & 2 deletions packages/histoire/src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js'
export interface CreateServerOptions {
port?: number
open?: boolean
host?: string | boolean
}

export async function createServer(ctx: Context, options: CreateServerOptions = {}) {
const getViteServer = async (collecting: boolean) => {
const { viteConfig, viteConfigFile } = await getViteConfigWithPlugins(collecting, ctx)

if (!collecting && options.open) {
viteConfig.server.open = true
if (!collecting) {
if (options.open) {
viteConfig.server.open = true
}

if (options.host) {
viteConfig.server.host = options.host
}
}

const server = await createViteServer(viteConfig)
Expand Down

0 comments on commit 1bdedeb

Please sign in to comment.