Webpack-dev-server: Config host and open

Created on 26 Aug 2019  路  4Comments  路  Source: webpack/webpack-dev-server

  • Operating System: Windows 10 Pro
  • Node Version: 10.15.3
  • NPM Version: 6.10.1
  • webpack Version: 4.34.0
  • webpack-dev-server Version: 3.7.1
  • Browser: Opera
  • [X] This is a bug
  • [ ] This is a modification request

Code

// webpack.config.js
devServer: {
    host: '0.0.0.0',
    port: 4002,
    overlay: true,
    open: true
}

Expected Behavior

I add the host: '0.0.0.0' in order to access the server via my IP address.
I add open: true in order to open the page in my browser automatically.
webpack-dev-server should open a tab with a proper url.

Actual Behavior

It opens the page in the browser with this url: 0.0.0.0:4002.
If I remove host: '0.0.0.0' from the config, I can not open the page with my url address anymore but only with localhost.

For Bugs; How can we reproduce the behavior?

For Features; What is the motivation and/or use-case for the feature?

Most helpful comment

Thanks @Loonride it works now 馃

  devServer: {
    host: '0.0.0.0',
    port: 4002,
    overlay: true,
    open: true,
    openPage: 'http://localhost:4002'
  }

All 4 comments

@PierBJX Try using the openPage option to specify the URL you want to open (https://webpack.js.org/configuration/dev-server/#devserveropenpage). The open option just tries to infer the URL you want using the host option.

Thanks @Loonride it works now 馃

  devServer: {
    host: '0.0.0.0',
    port: 4002,
    overlay: true,
    open: true,
    openPage: 'http://localhost:4002'
  }

@Loonride maybe we should handle this case, what are you thinking?

@Loonride maybe we should handle this case, what are you thinking?

Yes, should it just be this particular case where 0.0.0.0 becomes localhost? Because if 0.0.0.0 is the host option, we don't have any better guess as to what the user wants.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hnqlvs picture hnqlvs  路  3Comments

mischkl picture mischkl  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments

Jack-Works picture Jack-Works  路  3Comments

Ky6uk picture Ky6uk  路  3Comments