Skip to content

fix: migrate entry injection to hooks #3424

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

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions lib/utils/DevServerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,49 @@ class DevServerPlugin {

// use a hook to add entries if available
if (typeof webpack.EntryPlugin !== 'undefined') {
for (const additionalEntry of additionalEntries) {
new webpack.EntryPlugin(compiler.context, additionalEntry, {
// eslint-disable-next-line no-undefined
name: undefined,
}).apply(compiler);
}
// Register Entry Dependency in Factory
const EntryDependency = require('webpack/lib/dependencies/EntryDependency');
Copy link
Member

Choose a reason for hiding this comment

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

Avoid using this, webpack should public export this

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I send PR to webpack then?

Copy link
Member Author

Choose a reason for hiding this comment

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

compiler.hooks.compilation.tap(
'webpack-dev-server',
(compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set(
EntryDependency,
normalModuleFactory
);
}
);

// eslint-disable-next-line no-undefined
const entryOptions = { name: undefined };
compiler.hooks.make.tapAsync(
'webpack-dev-server',
(compilation, callback) => {
let entriesCompleted = 0;
const errors = [];
// Register additionalEntries
for (const additionalEntry of additionalEntries) {
const dependency = webpack.EntryPlugin.createDependency(
additionalEntry,
entryOptions
);
compilation.addEntry(
compiler.context,
dependency,
entryOptions,
// eslint-disable-next-line no-loop-func
(err) => {
if (err) {
errors.push(err);
}
entriesCompleted += 1;
if (entriesCompleted === additionalEntries.length) {
callback(errors[0]);
}
}
);
}
}
);
} else {
compilerOptions.entry = prependEntry(
compilerOptions.entry || './src',
Expand Down