-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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(utils): addEntries fix #2723
Conversation
Codecov Report
@@ Coverage Diff @@
## v4 #2723 +/- ##
==========================================
- Coverage 93.04% 92.85% -0.20%
==========================================
Files 39 39
Lines 1309 1330 +21
Branches 349 357 +8
==========================================
+ Hits 1218 1235 +17
- Misses 87 91 +4
Partials 4 4
Continue to review full report at Codecov.
|
a1becda
to
4db9c0a
Compare
compiler.hooks.make.tapAsync( | ||
{ | ||
name: 'webpack-dev-server', | ||
stage: -100, |
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.
@evilebottnawi @sokra I've added the tapAsync method here, but the issue I've found now is that something like this where multiple Servers are attached to a compiler no longer works:
const compiler = webpack(config);
const server1 = new Server(compiler, options1);
const server2 = new Server(compiler, options2);
as it results in something like Error: Conflicting entry option static = [object Object] vs [object Object]
This worked before, as there were tests that did this which are now broken. (These tests would usually close the old server before a new one was attached)
Should we go about this by making multiple servers on one compiler discouraged, or maybe a hacky method of disabling the old hook taps like in webpack/tapable#109 after the server is closed?
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.
Or I could also try to prevent duplicate entries by looking at the compilation globalEntry object.
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 added the hacky method for disabling old hook taps, but haven't added tests for it yet
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.
@Loonride I think we should prevent duplicate, in theory we can have property on compiler
to achieve this, we use same logic here https://github.com/webpack/webpack-dev-middleware/blob/master/src/utils/setupWriteToDisk.js#L9 (but it only for webpack@4)
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.
@evilebottnawi That is a good idea, do you think I should remove my closeCallback
method and replace it with setting something like compiler.hasWebpackDevServerMakeCallback = true
?
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 it is more clean hack 😄
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.
@evilebottnawi I agree it is more clean, but one issue I now see is that if the user does:
const compiler = webpack(config);
const server1 = new Server(compiler, options1);
server1.close(() => {
const server2 = new Server(compiler, options2);
});
If the options2
object results in a new set of entries, that will not be reflected in the compilation, since the old make callback would still be used.
@Loonride ready for review? |
@evilebottnawi Almost, but 2 things
|
@Loonride I think related webpack/webpack-dev-middleware#682, maybe you can provide example of configuration? |
It looks like the issue is here:
|
lib/Server.js
Outdated
@@ -50,7 +50,7 @@ class Server { | |||
this.wsHeartbeatInterval = 30000; | |||
|
|||
normalizeOptions(this.compiler, this.options); | |||
updateCompiler(this.compiler, this.options); | |||
this._closeCallback = updateCompiler(this.compiler, this.options); |
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.
do you agree with this naming since it is supposed to be an internal property?
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.
Yes 👍
@evilebottnawi Ready for review |
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 after release webpack-dev-server@4 we should focus on extracting hot and client stuff from webpack-dev-server to separate middleware (we already have webpack-hot-middlware and webpack-client-middleware, we need deprecate them too) and use hooks for modify compiler/compilation options, also after this we can refactor webpack-dev-server to plugin, what do you think?
Extracting is sounds good to me, but why do you want to deprecate them? You mean creating new libs...? |
Because they do the same, only in a dirty way, I think it will be easier for us to union all into the one project, it will be easier to maintain and fix
Yes, new, just maybe take name, webpack-hot-middleware sounds good |
// this invalidates old make callbacks | ||
compiler.webpackDevServerMakeCallbackCount += 1; | ||
} else { | ||
compiler.webpackDevServerMakeCallbackCount = 1; |
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.
My idea was to make a counter for callbacks, so that only the most recent callback will be used, fixing the problem I mentioned. Let me know if this seems too hacky.
3207c7d
to
dd66b7c
Compare
@Loonride Would you mind if I take this PR? |
@ylemkimon I think you can resent this PR, based on @Loonride activity, @Loonride is not available now if you resent this fix, I will be very thankful |
Cherry-picked from webpack#2723. Co-authored-by: Loonride <[email protected]>
For Bugs and Features; did you add new tests?
Yes
Motivation / Use-Case
This is a PR for: #2692 (comment)
Basically, we should not be re-injecting entries that the user provided, we should only inject webpack-dev-server entries, as the webpack compiler should already handle the user's entries
Breaking Changes
addEntries
util API has changed to take acompiler
argumentAdditional Info