Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@
"webpack-sources": "3.3.3"
},
"dependencies": {
"@module-federation/runtime-tools": "0.22.0",
"@rspack/binding": "workspace:*",
"@rspack/lite-tapable": "1.1.0"
},
"peerDependencies": {
"@module-federation/runtime-tools": ">=0.22.0",
"@swc/helpers": ">=0.5.1"
},
"peerDependenciesMeta": {
"@module-federation/runtime-tools": {
"optional": true
},
"@swc/helpers": {
"optional": true
}
Expand Down
27 changes: 22 additions & 5 deletions packages/rspack/src/container/ModuleFederationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ModuleFederationPlugin {

apply(compiler: Compiler) {
const { webpack } = compiler;
const paths = getPaths(this._options);
const paths = getPaths(this._options, compiler);
compiler.options.resolve.alias = {
'@module-federation/runtime-tools': paths.runtimeTools,
'@module-federation/runtime': paths.runtime,
Expand Down Expand Up @@ -283,7 +283,10 @@ function getRuntimePlugins(options: ModuleFederationPluginOptions) {
return options.runtimePlugins ?? [];
}

function getPaths(options: ModuleFederationPluginOptions): RuntimePaths {
function getPaths(
options: ModuleFederationPluginOptions,
compiler: Compiler,
): RuntimePaths {
if (IS_BROWSER) {
return {
runtimeTools: '@module-federation/runtime-tools',
Expand All @@ -292,9 +295,23 @@ function getPaths(options: ModuleFederationPluginOptions): RuntimePaths {
};
}

const runtimeToolsPath =
options.implementation ??
require.resolve('@module-federation/runtime-tools');
let runtimeToolsPath: string;
if (options.implementation) {
runtimeToolsPath = options.implementation;
} else {
try {
runtimeToolsPath = require.resolve('@module-federation/runtime-tools', {
paths: [compiler.context],
});
} catch (e) {
if ((e as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
throw new Error(
'Module Federation runtime is not installed. Please install it by running:\n\n npm install @module-federation/runtime-tools\n',
);
}
throw e;
}
}
const bundlerRuntimePath = require.resolve(
'@module-federation/webpack-bundler-runtime',
{ paths: [runtimeToolsPath] },
Expand Down
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 22 additions & 21 deletions tests/rspack-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
"test:hot": "cross-env RSPACK_HOT_TEST=true node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/@rstest/core/bin/rstest --config ./rstest.config.hot.ts --passWithNoTests"
},
"devDependencies": {
"@babel/core": "^7.28.5",
"@babel/preset-react": "^7.28.5",
"@module-federation/runtime-tools": "^0.22.0",
"@rspack/binding-testing": "workspace:*",
"@rspack/cli": "workspace:*",
"@rspack/core": "workspace:*",
"@rspack/binding-testing": "workspace:*",
"@rspack/plugin-preact-refresh": "1.1.4",
"@rspack/plugin-react-refresh": "^1.5.3",
"@rspack/test-tools": "workspace:*",
Expand All @@ -32,54 +35,52 @@
"acorn": "^8.15.0",
"babel-loader": "^10.0.0",
"babel-plugin-import": "^1.13.8",
"bundle-loader": "^0.5.6",
"chalk": "^4.1.2",
"coffee-loader": "^1.0.1",
"coffeescript": "^2.7.0",
"core-js": "3.47.0",
"css-loader": "^7.1.2",
"date-fns": "^4.1.0",
"es5-ext": "^0.10.64",
"exports-loader": "^5.0.0",
"file-loader": "^6.2.0",
"fork-ts-checker-webpack-plugin": "^9.1.0",
"graceful-fs": "^4.2.11",
"json-loader": "^0.5.7",
"html-loader": "^5.1.0",
"html-webpack-plugin": "^5.6.5",
"is-ci": "4.1.0",
"json-loader": "^0.5.7",
"json5": "^2.2.3",
"less": "4.4.2",
"less-loader": "^12.3.0",
"lodash": "^4.17.21",
"lodash-es": "^4.17.22",
"memfs": "4.51.1",
"mime-types": "^3.0.2",
"mini-svg-data-uri": "^1.4.4",
"node-polyfill-webpack-plugin": "^4.1.0",
"postcss-loader": "^8.2.0",
"postcss-pxtorem": "^6.1.0",
"prop-types": "^15.8.1",
"raw-loader": "^4.0.2",
"react": "^19.2.3",
"react-dom": "^19.2.3",
"react-refresh": "^0.18.0",
"rimraf": "^5.0.10",
"sass-loader": "^16.0.6",
"source-map": "^0.7.6",
"source-map-loader": "^5.0.0",
"style-loader": "^4.0.0",
"terser": "5.44.1",
"terser-webpack-plugin": "^5.3.16",
"toml": "^3.0.0",
"ts-loader": "^9.5.4",
"typescript": "^5.9.3",
"url-loader": "^4.1.1",
"wast-loader": "^1.14.1",
"webpack-sources": "3.3.3",
"worker-rspack-loader": "^3.1.2",
"exports-loader": "^5.0.0",
"@babel/preset-react": "^7.28.5",
"coffee-loader": "^1.0.1",
"coffeescript": "^2.7.0",
"es5-ext": "^0.10.64",
"is-ci": "4.1.0",
"less": "4.4.2",
"lodash-es": "^4.17.22",
"mime-types": "^3.0.2",
"bundle-loader": "^0.5.6",
"rimraf": "^5.0.10",
"url-loader": "^4.1.1",
"terser-webpack-plugin": "^5.3.16",
"ts-loader": "^9.5.4",
"@babel/core": "^7.28.5",
"date-fns": "^4.1.0",
"fork-ts-checker-webpack-plugin": "^9.1.0",
"json5": "^2.2.3",
"prop-types": "^15.8.1",
"xxhashjs": "^0.2.2",
"yamljs": "^0.3.0"
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/en/plugins/webpack/module-federation-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { Stability, ApiMeta } from '@components/ApiMeta';

This plugin implements [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced).

:::tip
This plugin requires `@module-federation/runtime-tools`. Please install it manually:

```bash
npm install @module-federation/runtime-tools
```

:::

## Example

```js title="rspack.config.mjs"
Expand Down
9 changes: 9 additions & 0 deletions website/docs/zh/plugins/webpack/module-federation-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { Stability, ApiMeta } from '@components/ApiMeta';

该插件实现了 [Module Federation 1.5](https://github.com/module-federation/universe/tree/main/packages/enhanced)。

:::tip
该插件需要依赖 `@module-federation/runtime-tools`,请手动安装:

```bash
npm install @module-federation/runtime-tools
```

:::

## 示例

```js title="rspack.config.mjs"
Expand Down
Loading