Skip to content

Add CLI and config option to auto assign port #1191

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

Closed
1 of 3 tasks
robert-prib-polestar opened this issue Nov 15, 2017 · 6 comments
Closed
1 of 3 tasks

Add CLI and config option to auto assign port #1191

robert-prib-polestar opened this issue Nov 15, 2017 · 6 comments

Comments

@robert-prib-polestar
Copy link

robert-prib-polestar commented Nov 15, 2017

  • Operating System: N/A
  • Node Version: N/A
  • NPM Version: N/A
  • webpack Version: N/A
  • webpack-dev-server Version: N/A
  • This is a bug
  • This is a feature request
  • This is a modification request

Code

Example code for port auto assign

This example script checks if the current port is in use and keeps trying attempting to start the dev server by traversing up by 1 based on the provided starting port.
https://gist.github.com/robert-prib-polestar/29cc8fab3eb83602009df3fbdb626ac4

Motivation / Use Case

  • It's useful to load multiple instances of the same project locally when you want to compare builds.
  • It's annoying to have to alter the package.json scripts to start up a new dev server with a different port.
  • Within projects, I often have multiple scripts within the package.json to start dev-servers with different environment variables and other options set. It's handy to be able to easily load up multiple dev servers without defining a specific port.
@shellscape
Copy link
Contributor

@robert-prib-polestar have you tried using a port set to 0? that should do it.

@robert-prib-polestar
Copy link
Author

@shellscape I will give it a go, didn't realise that!

@robert-prib-polestar
Copy link
Author

This can be closed, I now realised this project uses portfinder to assign a new port if the current one is in use. I don't believe there is any need to set port to 0 looking at current implementation?

I just realised that my project is still stuck on old version of webpack and webpack-dev-server and we cant use this feature until we upgrade to webpack2+, as portfinder plugin wasnt added to webpack-dev-server unil version 2.2.0.

@shellscape
Copy link
Contributor

@robert-prib-polestar thanks for following up. and wow, webpack 1.x is really old! the performance and fidelity improvements alone are worth the upgrade to webpack 3!

@montogeek
Copy link
Member

@shellscape What you think about using https://github.com/node-modules/detect-port to do this?

@shellscape
Copy link
Contributor

@montogeek I no longer maintain this module and have shifted my focus to https://www.npmjs.com/package/webpack-serve. webpack-serve uses https://github.com/sindresorhus/get-port and I believe webpack-dev-server does as well iirc.

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

3 participants