Skip to content

Commit

Permalink
Fix injectRefreshLoader performance issue (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
marco2216 committed Sep 26, 2022
1 parent 5b0ef9b commit e0f8a42
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit e0f8a42

Please sign in to comment.