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

feat: add host config to histoire dev #743

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 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
Loading