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

[1.0] Automatically open browser when running gatsby develop (like create-react-app) #1531

Closed
prayash opened this issue Jul 16, 2017 · 11 comments

Comments

@prayash
Copy link
Contributor

prayash commented Jul 16, 2017

Is it possible to implement this feature? I find it very handy when starting up the dev server.

Looking through create-react-app scripts/start.js, it seems that they use an external openBrowser package like so:

const openBrowser = require('react-dev-utils/openBrowser')

// then open the dev server url with the package
openBrowser(urls.localUrlForBrowser);

If it's a trivial change, I'd love to take a stab at it!

@oscar-b
Copy link
Contributor

oscar-b commented Jul 16, 2017

Try gatsby develop --open

  Usage: develop [options]

  Start development server. Watches files and rebuilds and hot reloads if something changes

  Options:

    -h, --help         output usage information
    -H, --host <url>   Set host. Defaults to localhost
    -p, --port <port>  Set port. Defaults to 8000
    -o, --open         Open the site in your browser for you.

@prayash
Copy link
Contributor Author

prayash commented Jul 16, 2017

Ahh! Should've looked that up before posting this. Sorry about that and thanks for the quick response!

@prayash prayash closed this as completed Jul 16, 2017
@KyleAMathews
Copy link
Contributor

Opening the site by default is an interesting default. @prayasht do you really like this? We could change the default. I haven't used CRA much or other systems which open pages by default. Is there other tools that do this?

The only downside I see is it grabs the focus of your OS which can be annoying.

@KyleAMathews KyleAMathews reopened this Jul 18, 2017
@oscar-b
Copy link
Contributor

oscar-b commented Jul 18, 2017

I don't like th default of CRA (you can change it with config though), it's quite annoying and you end up with a lot of tabs. As long as it's possible to configure, I think either default is fine.

@prayash
Copy link
Contributor Author

prayash commented Jul 18, 2017

@oscar-b On my machine (macOS + Chrome), if an instance is already open in a tab, it simply refreshes it. I've never had it open new instances every time I run the dev server.

Honestly, I like it and I just changed my npm script to gatsby develop --open so that's easy enough for me. Not sure about others though!

@KyleAMathews
Copy link
Contributor

Let's leave this open for a while to see if anyone else has strong feelings about it

@VerteDinde
Copy link

Just chiming in as a create-react-app user to say that I really like the app to open as a default; gatsby develop --open works fine for me as well, though.

@secretfader
Copy link

--open should not be the default.

I share the same dislike for Gatsby taking control of my OS windows, even just to launch a browser. I changed the default behavior in CRA the moment I installed it.

This can be easily scripted. Most sites already wrap gatsby build as npm run build — my two cents? --open can be just as easily included there, in your package.json, on a project-by-project basis.

@youfoundron
Copy link
Contributor

Going to chime in and say that --open should not be a default.

@sebastienfi
Copy link
Contributor

I too agree, -o shouldn't be default.

@KyleAMathews
Copy link
Contributor

Leaving it not as the default :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants