From 0cbd697279f7fe3eb2b4e58d887b4c9f574adcce Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 23 Aug 2022 11:12:33 +0200 Subject: [PATCH] chore: reworking the modulescope config Signed-off-by: blam --- packages/cli/src/lib/bundler/config.ts | 39 +++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index 2aac38732d..882926d051 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -139,14 +139,24 @@ export async function createConfig( new LinkedPackageResolvePlugin(paths.rootNodeModules, externalPkgs), ]; - if (!isDev) { - resolvePlugins.push( - new ModuleScopePlugin( - [paths.targetSrc, paths.targetDev], - [paths.targetPackageJson], - ), - ); - } + // These files are required by the transpiled code when using React Refresh. + // They need to be excluded to the module scope plugin which ensures that files + // that exist in the package are required. + const reactRefreshFiles = [ + require.resolve( + '@pmmmwh/react-refresh-webpack-plugin/lib/runtime/RefreshUtils.js', + ), + require.resolve('@pmmmwh/react-refresh-webpack-plugin/overlay/index.js'), + require.resolve('react-refresh'), + ]; + + resolvePlugins.push( + new ModuleScopePlugin( + [paths.targetSrc, paths.targetDev], + [paths.targetPackageJson, ...reactRefreshFiles], + ), + ); + return { mode: isDev ? 'development' : 'production', profile: false, @@ -228,17 +238,12 @@ export async function createBackendConfig( const resolvePlugins: webpack.ResolvePluginInstance[] = [ new LinkedPackageResolvePlugin(paths.rootNodeModules, externalPkgs), + new ModuleScopePlugin( + [paths.targetSrc, paths.targetDev], + [paths.targetPackageJson], + ), ]; - if (!isDev) { - resolvePlugins.push( - new ModuleScopePlugin( - [paths.targetSrc, paths.targetDev], - [paths.targetPackageJson], - ), - ); - } - return { mode: isDev ? 'development' : 'production', profile: false,