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

Open default browser if --open option is given #329

Merged
merged 2 commits into from
Jan 11, 2016

Conversation

SpaceK33z
Copy link
Member

This will open your default browser with the app url if you add the --open option to the CLI.

Fixes #311

@supersonicclay
Copy link

Not sure if this is environmental for me, but I get this error:

Error: ENOENT: no such file or directory, open '.....\node_modules\webpack-dev-server\client\live.bundle.js'

@sokra
Copy link
Member

sokra commented Dec 3, 2015

@claycephas npm run prepublish if you want to run it from git checkout.

@SpaceK33z it opens the wrong uri when inline: false.

@SpaceK33z
Copy link
Member Author

@sokra, how did you test this? I'm using cd example && node ../bin/webpack-dev-server.js --open, and it opens http://localhost:8080/ for me, which is correct.

Even when I add this it seems to work fine:

devServer: {
    inline: false
}

@sokra
Copy link
Member

sokra commented Dec 3, 2015

It should open the printed url.

http://localhost:8080/webpack-dev-server/ in non-inline mode.

@SpaceK33z
Copy link
Member Author

Okay, I intentionally did it without the /webpack-dev-server part, but I see now that's quite confusing. It's fixed now :).

Thank you for merging all my PR's so far and the constructive feedback @sokra :).

@supersonicclay
Copy link

ok, I updated my package.json file to have this entry:

"webpack-dev-server": "CodeYellowBV/webpack-dev-server#98fd2f45b4a81"

then ran

npm install
cd node_modules/webpack-dev-server
npm run prepublish

now this works as expected

./node_modules/.bin/webpack-dev-server --open

Please merge!

sokra added a commit that referenced this pull request Jan 11, 2016
Open default browser if --open option is given
@sokra sokra merged commit 83cff95 into webpack:master Jan 11, 2016
@sokra
Copy link
Member

sokra commented Jan 11, 2016

Thanks...

Could you also update documentation page to include this CLI option?

@SpaceK33z
Copy link
Member Author

@sokra, I have edited the wiki to include the --open option.

@SpaceK33z SpaceK33z deleted the open-browser branch January 11, 2016 21:21
@sandwichsudo
Copy link

Is it possible to use this option when opening webpackDevServer from a node script?
eg

const server = new WebpackDevServer(compiler, {
    hot : true,
    harmony : true,
    host : '0.0.0.0'
});
server.listen(8080);

@SpaceK33z
Copy link
Member Author

@sandwichsudo, nope, not at the moment.

@Gopikrishna19
Copy link

This doesn't open browser for me.. am I missing something?
Here's my package:

"scripts": {
  "start": "babel-node server/index.js | webpack-dev-server --open"
},
"devDependencies": {
  "webpack-dev-server": "^1.14.1"
}

And webpack.config:

entry: [
  'webpack-dev-server/client?http://localhost:8080',
  'webpack/hot/only-dev-server',
  './client/index.js'
],
devServer: {
    contentBase: './dist',
    hot: true,
    noInfo: true
}

@SpaceK33z
Copy link
Member Author

@Gopikrishna19, apparently it was not part of the 1.14.1 release. In the next 2.0 version it should work.

@GuyMograbi
Copy link

webpack is awesome!

just reached here. half a year later. is it possible to have a patch for this as 2.x is not out yet? I will gladly help if you guide me.

@SpaceK33z
Copy link
Member Author

@GuyMograbi, I happen to be working on a v1 release.

@calledT
Copy link

calledT commented Sep 3, 2016

It's better I could decide which url to open with the --open option is string.Because I want to add querystring to the open url or the default name of my html is not index.

@LucienLee
Copy link

Before webpack 2.0 released, I think using [opn](https://www.npmjs.com/package/opn) module is the simplest to open any url in browser.

@controversial
Copy link

Is it possible to specify this in webpack.config.js?

@alflennik
Copy link

I'd love to see this in the config.

devServer: {
  open: true
}

@jonkoops
Copy link

@alflennik Maybe open a new issue with that as a feature request?

@pavel06081991
Copy link

@SpaceK33z, how to pass open option when webpack-dev-server is used as module? (https://github.com/webpack/docs/wiki/webpack-dev-server#api)

@lucaritossa
Copy link

Is there a way to specify a different url path or the standard url http://host:port will be always used?
I need to open a url similar to http://host:port/my-custom-path/ (angular project inside an ASP.NET MVC existing project)

@TrySound
Copy link

@pavel06081991 No way. It's only CLI feature.

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

Successfully merging this pull request may close these issues.