Skip to content

Commit

Permalink
fix: failed to load MF remote modules when using server.base (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 22, 2024
1 parent e90b5d1 commit 2152285
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
39 changes: 39 additions & 0 deletions e2e/cases/module-federation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,45 @@ rspackOnlyTest(
},
);

rspackOnlyTest(
'should run module federation in development mode with server.base',
async ({ page }) => {
writeButtonCode();

const remotePort = await getRandomPort();

process.env.REMOTE_PORT = remotePort.toString();

const remoteApp = await dev({
cwd: remote,
rsbuildConfig: {
server: {
base: '/remote',
},
},
});
const hostApp = await dev({
cwd: host,
rsbuildConfig: {
server: {
base: '/host',
},
},
});

await gotoPage(page, remoteApp);
await expect(page.locator('#title')).toHaveText('Remote');
await expect(page.locator('#button')).toHaveText('Button from remote');

await gotoPage(page, hostApp);
await expect(page.locator('#title')).toHaveText('Host');
await expect(page.locator('#button')).toHaveText('Button from remote');

await hostApp.close();
await remoteApp.close();
},
);

rspackOnlyTest(
'should allow remote module to perform HMR',
async ({ page }) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/plugins/moduleFederation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isRegExp } from 'node:util/types';
import { rspack } from '@rspack/core';
import type { RspackPluginInstance } from '@rspack/core';
import { DEFAULT_ASSET_PREFIX } from '../constants';
import type { CacheGroup, RsbuildPlugin, Rspack } from '../types';

/**
Expand Down Expand Up @@ -115,7 +114,7 @@ export function pluginModuleFederation(): RsbuildPlugin {
const originalConfig = api.getRsbuildConfig('original');
if (
originalConfig.dev?.assetPrefix === undefined &&
config.dev.assetPrefix === DEFAULT_ASSET_PREFIX
config.dev.assetPrefix === config.server?.base
) {
config.dev.assetPrefix = true;
}
Expand Down

0 comments on commit 2152285

Please sign in to comment.