Skip to content

Commit dbc7318

Browse files
committed
fix(modern-js-plugin): set bridge.disableAlias true when installing @module-federation/bridge-react
1 parent 3515331 commit dbc7318

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/modernjs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Patch Changes
66

7+
- fix(modern-js-plugin): set bridge.disableAlias true when installing @module-federation/bridge-react
78
- 41ee332: chore(modern-js-plugin): re-export all bridge react
89
- Updated dependencies [8004e95]
910
- Updated dependencies [0bf3a3a]

packages/modernjs/src/cli/configPlugin.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
import fs from 'fs';
23
import { getIPV4, isWebTarget, skipByTarget } from './utils';
34
import { moduleFederationPlugin, encodeName } from '@module-federation/sdk';
45
import { bundle } from '@modern-js/node-bundle-require';
@@ -162,6 +163,26 @@ export const patchMFConfig = (
162163

163164
const runtimePlugins = [...(mfConfig.runtimePlugins || [])];
164165

166+
try {
167+
const nodeModulesPath = path.resolve(process.cwd(), 'node_modules');
168+
const bridgeReactPath = path.join(
169+
nodeModulesPath,
170+
'@module-federation/bridge-react',
171+
);
172+
if (
173+
fs.existsSync(bridgeReactPath) &&
174+
(!mfConfig?.bridge || !mfConfig.bridge.disableAlias)
175+
) {
176+
mfConfig.bridge = {
177+
disableAlias: true,
178+
};
179+
logger.debug(
180+
`${PLUGIN_IDENTIFIER} use "@module-federation/modern-js/react" instead of "@module-federation/bridge-react" !`,
181+
);
182+
}
183+
} catch (e) {
184+
// noop
185+
}
165186
patchDTSConfig(mfConfig, isServer);
166187

167188
injectRuntimePlugins(

0 commit comments

Comments
 (0)