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: check for name of HotModuleReplacementPlugin to avoid RangeError #2146

Merged
merged 3 commits into from
Jul 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions lib/utils/addEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ function addEntries(config, options, server) {
config.plugins = config.plugins || [];
if (
!config.plugins.find(
(plugin) =>
plugin.constructor === webpack.HotModuleReplacementPlugin
// Check for the name rather than the constructor reference in case
// there are multiple copies of webpack installed
(plugin) => plugin.constructor.name === 'HotModuleReplacementPlugin'
)
) {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
Expand Down
20 changes: 20 additions & 0 deletions test/server/utils/addEntries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ describe('addEntries util', () => {
]);
});

it("should not add the HMR plugin again if it's already there from a different webpack", () => {
const existingPlugin = new webpack.BannerPlugin('bruce');

// Simulate the inclusion of another webpack's HotModuleReplacementPlugin
class HotModuleReplacementPlugin {}

const webpackOptions = Object.assign({}, config, {
plugins: [new HotModuleReplacementPlugin(), existingPlugin],
});
const devServerOptions = { hot: true };

addEntries(webpackOptions, devServerOptions);

expect(webpackOptions.plugins).toEqual([
// Nothing should be injected
new HotModuleReplacementPlugin(),
existingPlugin,
]);
});

it('should can prevent duplicate entries from successive calls', () => {
const webpackOptions = Object.assign({}, config);
const devServerOptions = { hot: true };
Expand Down