Skip to content

Add CLI and config option to auto assign port #1191

Closed

Description

@robert-prib-polestar
  • 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.

Activity

  1. shellscape commented on Nov 15, 2017

    @shellscape
    Contributor

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

  2. robert-prib-polestar commented on Nov 16, 2017

    @robert-prib-polestar
    Author

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

  3. robert-prib-polestar commented on Nov 16, 2017

    @robert-prib-polestar
    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.

  4. shellscape commented on Nov 16, 2017

    @shellscape
    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!

  5. montogeek commented on Mar 28, 2018

    @montogeek
  6. shellscape commented on Mar 28, 2018

    @shellscape
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions