chore: reworking the modulescope config

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-08-23 11:12:33 +02:00
parent c5b6fa3598
commit 0cbd697279
+22 -17
View File
@@ -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,