-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor(utils): addEntries to DevServerPlugin #2844
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
Conversation
Codecov Report
@@ Coverage Diff @@
## v4 #2844 +/- ##
==========================================
- Coverage 93.08% 93.02% -0.07%
==========================================
Files 40 39 -1
Lines 1331 1305 -26
Branches 354 355 +1
==========================================
- Hits 1239 1214 -25
+ Misses 88 87 -1
Partials 4 4
Continue to review full report at Codecov.
|
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.
Anyway good job and big thanks
a39076c
to
1739b5a
Compare
1739b5a
to
17b6500
Compare
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.
Looks good, let's rename file and I think we can merge it, good job and big thanks again, you are great ⭐
Forget about one - do we have multi compiler tests? |
This comment has been minimized.
This comment has been minimized.
webpack-dev-server/test/server/utils/updateCompiler.test.js Lines 142 to 151 in 17b6500
|
17b6500
to
ac40767
Compare
If I add a module declaration file ( |
lib/utils/DevServerPlugin.js
Outdated
// eslint-disable-next-line no-undefined | ||
undefined, | ||
null, | ||
].includes(compilerOptions.target); |
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 found better way to do it in webpack@5, let's check:
const isWebTarget = compiler.optons.externalsPresets
? compiler.optons.externalsPresets.web
: // Old logic 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.
Should we add client entries when compiler.optons.externalsPresets.web === null
, i.e., targets are mixed, e.g., ['web', 'node']
?
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.
No, only when it is web
, if it is not web
and still in browser (I don't know this case 😄 ) you should use injectHot: 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.
Very good job, only one improvement and we can merge it
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.
Let's fix tests and merge it
This comment has been minimized.
This comment has been minimized.
lib/utils/DevServerPlugin.js
Outdated
) { | ||
// add and apply the HMR plugin, if it didn't exist before. | ||
const plugin = new webpack.HotModuleReplacementPlugin(); | ||
compilerOptions.plugins.push(plugin); |
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.
Just apply
no need to push it in plugins
array
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.
If it is not pushed to plugins
, it'd add it again if the plugin is applied again.
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.
Can you clarify? We should not touch compilerOptions
, only use plugin.apply(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.
If newly applied plugins are not added to config.plugins
, then in
const compiler = webpack(config);
const server1 = new Server(compiler, options1); // calls devServerPlugin.apply(compiler)
server1.close(() => {
const server2 = new Server(compiler, options2); // calls devServerPlugin.apply(compiler), again
});
each time the Server constructor is called, HMR plugin and this plugin will be applied. So they will be applied twice, causing duplicate hooks and entries.
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 using a single compiler instance across multiple dev-server instances should be reconsidered, as it's impossible to remove or update hooks and it's not possible to persist state (whether plugins and hooks are added, etc.) without touching compiler
or compiler.options
. It seems it was not properly supported before.
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 here is the architecture problem, if we will be plugin we will not have this problem, so we need focus for v5 on refactor to plugin
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.
We can mark it as limitation now
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.
Removed compilerOptions.plugins.push(plugin)
. This PR is ready to merge.
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.
The plugin would have the same limitation, since the second dev-server ( Do you mean refactoring the whole package into a plugin?server2
) cannot get or modify the plugin added by the first dev-server (server1
).
2619361
to
7c4af08
Compare
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.
Good job and big thanks, we need focus on CLI, it is the last issue (hope)
We need remove
What do you think? |
How about we defer (delegate) to // maybe throw a friendly error if webpack is not installed
process.argv.splice(2, 0, 'serve');
require('webpack/bin/webpack'); ? |
Sounds good, but am afraid webpack can change logic too in future and we will can broken again, so I think it would be better to use |
For Bugs and Features; did you add new tests?
Yes
Motivation / Use-Case
#2841 (comment)
Removed
DevServerEntryPlugin
and movedaddEntries
intoDevServerPlugin
.Breaking Changes
Yes.
lib/utils/addEntries
(exported asServer.addDevServerEntrypoints
) function is nowlib/utils/DevServerPlugin
, a webpack plugin and no longer exported. It now takes a webpack-dev-server option as a constructor argument and deduplication should be handled by including only a single instance of the plugin.should be changed to
Furthermore, using HotModuleReplacementPlugin from another webpack installation is not supported and should be avoided.
Additional Info
All changes are refactoring, so ignoring whitespace would help reviewing the diff.