webpack-cli: serve does not work with multi-server
Describe the bug
We’re having issues updating to webpack 5 and webpack serve
. Our project is divided into multiple webpack configurations. Say for example we have one configuration for a SPA /login/
, /portal/
, our application for end users and /admin/
for our administrators. We do this, so that every SPA when hosted belongs into its own folder and we can easily make sure that critical code like in our /admin/
SPA is never served outside of intranet. Now to test locally, we use webpack-dev-server’s multi project configuration. Every SPA is identifiable by an unique publicPath
(e. g. /admin
). This worked beautifully with webpack-dev-server, but with webpack 5 and webpack-cli this is no longer the case. We use multiple webpack configurations to test our
We used to use webpack-dev-server
to start our development server directly, however as I understand that is no longer working with webpack 5.
What is the current behavior?
Webpack-cli outputs a an error message:
Error: Unique ports must be specified for each devServer option inyour webpack configuration. Alternatively, run only 1 devServer config using the--config-name flag to specify your desired config.
at Object.startDevServer [as default]
To Reproduce
Steps to reproduce the behavior: https://github.com/webpack/webpack-cli/blob/master/test/serve/basic/multi-dev-server.config.js without the explicit ports does show my use case perfectly.
Expected behavior
If publicPath
s for configurations are unique, webpack serve
should be able to serve them from the same port.
Screenshots
Please paste the results of webpack-cli info
here, and mention other relevant information
Additional context
Maybe this was first introduced with https://github.com/webpack/webpack-cli/pull/1649 A possible solution might be to change https://github.com/webpack/webpack-cli/blob/ec3baa84479984921e40cd7113e4ab6a14723a7a/packages/serve/src/startDevServer.ts#L14 to add an additional check for unique publicPath
s if ports are not unique.
Thanks a lot, Christian
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 23 (11 by maintainers)
First of all thank you, @alexander-akait! You are very right that my example works fine with webpack5, I just checked. However, you were also correct that the multiple
devServer
configurations cause my issue. I always thought they would apply per configuration and not globally.To everyone running into the same issue I have adapted my initial example into a
Is it just me or is the the multi-compiler feature lacking documentation? I would be happy to help if hands are needed with that, since it is an invaluable feature for me.
@Christian24 @alexander-akait, thanks for your work on this issue!!!
This same problem just came up for me this week.
@Christian24’s detailed notes helped me get our local dev up and running again! 🙏
@webpack/cli-team I think we can implement it in better way -
--no-dev-server [config-name]
(only forwebpack serve
, so should be implement there), should solve most of problemsI think we will do the same https://github.com/webpack/webpack/pull/12671, but for dev server
I will open an issue in docs repo don’t worry, I need time to think how we can make it better
Sure, maybe here: https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations? I wouldn’t know if I would find it there though. I think the whole topic might need more documentation or is there more? Would it be a good idea to open an issue at https://github.com/webpack/webpack.js.org?
Let’s keep open, I want to search right way for this or update docs with the limitation (official)
@Christian24 Yep, I think it should be like this, but changing syntax in config files will be a big problem, I need think about it
Well, multiple entries wouldn’t work in our case, since that wouldn’t allow us to specify the correct
publicPath
per entry, right?I am a bit confused why this no longer works, since this worked just fine in webpack@4 and I am honestly a bit uncertain as to what our upgrade path can be.