Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

anshumanv
Copy link
Member

What kind of change does this PR introduce?

fix

Did you add tests for your changes?
Not yet.

If relevant, did you update the documentation?
NA

Summary

  • pass additional devServer config from config file to the server

Does this PR introduce a breaking change?

No

Other information
Fixes #1469

if (socket) {
options.socket = socket;
}

const server = new Server(compiler, options);
// Compose config from the CLI and devServer object from webpack config
const serverConfig = { ...devServerOptions, ...options };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem - this way we won't be able to override default options unless specified via flag. eg. clientLogLevel by default is set to 'info', so if we pass any other option in devServer, it won't take precedence, but we also need to support flags like --hot and override them with the devServer config so that's a dilemma

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI args should be override config values, what is a problem, can you clarify with examples?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need to override config values then I think we're fine with devServer options taking precedence.

@anshumanv anshumanv marked this pull request as ready for review April 16, 2020 19:26
@anshumanv anshumanv requested a review from a team as a code owner April 16, 2020 19:26
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 };
Copy link
Contributor

Choose a reason for hiding this comment

The 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 devServer regardless of what the user has set for that value in devServer? Yes, this is an issue.

Our goal is that CLI args should take precedence over devServer, so this line here is not the perfect solution.

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 commander as the CLI flags parser. Ideally we can pass a CLI options object into startDevServer which indicates whether each flag was defaulted to, or whether the user explicitly provided the flag.

Alternatively, we should just not have dev server CLI flag default values.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 devServer regardless of what the user has set for that value in devServer? Yes, this is an issue.

Precisely.

That makes sense to me, lets revisit this after we're on the new parser.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 --hot flag, when passed will appear in the CLI options object, and if devServer contains hot: false then the CLI option won't override this way, but nobody does will explicitly pass hot: false in their config right, since it's default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @Loonride how do we proceed here?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 webpack-cli help serve. Will think about this a bit and come back to it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you get any findings about this @Loonride ?

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, let me know your thoughts :)

@@ -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 || {};
Copy link
Member

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 contain devServer, we need to think how to handle it, do we have --name option to choose compiler?

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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 output warning about you need specify name of compiler, in future we will dev server as plugin and we don't need this hack

@anshumanv
Copy link
Member Author

Closing in favour of #1649

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serve command not passing webpack devServer config to webpack-dev-server
5 participants