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 injectRefreshLoader performance issue #669

Merged
merged 2 commits into from Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/utils/injectRefreshLoader.js
Expand Up @@ -13,6 +13,8 @@ const path = require('path');
*/

const resolvedLoader = require.resolve('../../loader');
const reactRefreshPath = path.dirname(require.resolve('react-refresh'));
const refreshUtilsPath = path.join(__dirname, '../runtime/RefreshUtils');

/**
* Injects refresh loader to all JavaScript-like and user-specified files.
Expand All @@ -31,8 +33,8 @@ function injectRefreshLoader(moduleData, injectOptions) {
// Skip react-refresh and the plugin's runtime utils to prevent self-referencing -
// this is useful when using the plugin as a direct dependency,
// or when node_modules are specified to be processed.
!moduleData.resource.includes(path.dirname(require.resolve('react-refresh'))) &&
!moduleData.resource.includes(path.join(__dirname, '../runtime/RefreshUtils')) &&
!moduleData.resource.includes(reactRefreshPath) &&
!moduleData.resource.includes(refreshUtilsPath) &&
// Check to prevent double injection
!moduleData.loaders.find(({ loader }) => loader === resolvedLoader)
) {
Expand Down