DEV Community

Peter Lau
Peter Lau

Posted on • Originally published at quickanswer.awesomefe.dev

2

Hugo |> Dev Server Open Browser


IF YOU JUST SOLVED SOME PROBLEM, WELCOME TO DM qaRabbit ON TWITTER, OR CREATE A PULL REQUEST IN GITHUB REPO.

Why hugo dev server can't open browser tab automatically?

Modify hugo source code will definitely solve this issue.

Or we can use two simpler ways:

  • use some program to run command hugo server and open_browser in parallel

  • use simple command sleep

Here is the second way on macOS: (open command only works on macOS)

#!/bin/bash

LOCAL_URL=http://localhost:1313

open_browser () {
  duration=${1:-3}
  sleep $duration
  echo 'After '$duration
  # change open command to proper one
  open --new -a "Google Chrome" --args $LOCAL_URL
}

open_browser 1 &
hugo server

Reference:

https://github.com/gohugoio/hugo/issues/6293
https://www.cyberciti.biz/faq/how-to-run-command-or-code-in-parallel-in-bash-shell-under-linux-or-unix/
https://zwbetz.com/open-a-new-google-chrome-tab-or-window-via-command-line-on-mac"

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started