From e0f8a427e1aa563a53a5f693e8a1f81a19c41129 Mon Sep 17 00:00:00 2001 From: Marco Sylvestersen Date: Mon, 26 Sep 2022 03:27:31 +0200 Subject: [PATCH] Fix injectRefreshLoader performance issue (#669) --- lib/utils/injectRefreshLoader.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/utils/injectRefreshLoader.js b/lib/utils/injectRefreshLoader.js index 16cd9f7c..86b42abc 100644 --- a/lib/utils/injectRefreshLoader.js +++ b/lib/utils/injectRefreshLoader.js @@ -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. @@ -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) ) {