-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
fix: pass devServer args to server options #1470
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,21 +11,25 @@ import Server from 'webpack-dev-server/lib/Server'; | |
*/ | ||
export default function startDevServer(compiler, options): void { | ||
const firstWpOpt = compiler.compilers ? compiler.compilers[0].options : compiler.options; | ||
const devServerOptions = firstWpOpt.devServer || {}; | ||
let devServerOptions = firstWpOpt.devServer || {}; | ||
|
||
// set default host and port | ||
devServerOptions = { host: 'localhost', port: 8080, ...devServerOptions }; | ||
|
||
const host = options.host || devServerOptions.host || 'localhost'; | ||
const port = options.port || devServerOptions.port || 8080; | ||
// socket should not have a default value, because it should only be used if the | ||
// user explicitly provides it | ||
const socket = options.socket || devServerOptions.socket; | ||
|
||
options.host = host; | ||
options.port = port; | ||
if (socket) { | ||
options.socket = socket; | ||
} | ||
|
||
const server = new Server(compiler, options); | ||
// Compose config from the CLI and devServer object from webpack config | ||
const serverConfig = { ...options, ...devServerOptions }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I understand what you are saying. Do you mean the issue is that if a CLI flag has a default value, it will override Our goal is that CLI args should take precedence over What we need to do is find a way to check if the user has actually provided the CLI flag, or if it is just getting passed in as a default value. It might be easier to hold off on this until we swap over to Alternatively, we should just not have dev server CLI flag default values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Precisely. That makes sense to me, lets revisit this after we're on the new parser. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you find a case when we don't want the devServer config to override? I could think of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /cc @Loonride how do we proceed here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the goal may be to just make dev server flags not set default values. If we do that, this shouldn't be an issue. But in that case it would still be nice for users to see what values are defaulted to later on when they do like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you get any findings about this @Loonride ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the delay, I can look at this more closely now that we are close to webpack-dev-server v4 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome, let me know your thoughts :) |
||
|
||
const { host, port } = serverConfig; | ||
|
||
const server = new Server(compiler, serverConfig); | ||
server.listen(socket || port, host, (err): void => { | ||
if (err) { | ||
throw err; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not entirely true. Second compiler also can contains
devServer
. To be honestly both can containdevServer
, we need to think how to handle it, do we have--name
option to choose compiler?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can run for both of them in parallel as they both would be configured for different entry points. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the merge strategy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming you are referring to merger of CLI options with config then I think you may use same strategy for each complier. Just CLI provided options would be same for each of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should look at all compilers, if you have two
devServer
outputwarning
about you need specifyname
of compiler, in future we will dev server as plugin and we don't need this hack