From ddb29fa73a177a77ba6559f1f264ea0748d962b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor?= Date: Thu, 5 Nov 2026 13:47:47 +0100 Subject: [PATCH] fix: publish a README with the tauri-plugin-module-federation crate --- .github/workflows/ci.yml | 2 + packages/tauri-plugin/Cargo.toml | 1 + packages/tauri-plugin/README.md | 82 ++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 packages/tauri-plugin/README.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e653129..e88d865 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,5 +36,7 @@ jobs: - run: pnpm release:sync:check - run: cargo fmt --all --check - run: pnpm build:ci + - name: Check crate package includes README + run: cargo package --list --locked --allow-dirty --manifest-path packages/tauri-plugin/Cargo.toml | grep -x README.md - run: cargo test -p tauri-plugin-module-federation - run: pnpm pack:tauri diff --git a/packages/tauri-plugin/Cargo.toml b/packages/tauri-plugin/Cargo.toml index a996624..f71fcf5 100644 --- a/packages/tauri-plugin/Cargo.toml +++ b/packages/tauri-plugin/Cargo.toml @@ -4,6 +4,7 @@ version = "1.0.0" authors = ["Néstor López "] license = "MIT" description = "Tauri plugin for Module Federation remote loading and offline cache fallback." +readme = "README.md" homepage = "https://github.com/module-federation/tauri-plugin-module-federation" repository = "https://github.com/module-federation/tauri-plugin-module-federation" edition = "2021" diff --git a/packages/tauri-plugin/README.md b/packages/tauri-plugin/README.md new file mode 100644 index 0000000..26ffbd3 --- /dev/null +++ b/packages/tauri-plugin/README.md @@ -0,0 +1,82 @@ +# tauri-plugin-module-federation + +Tauri 2 plugin that loads [Module Federation](https://module-federation.io) remotes through an `mf://` custom protocol, caches every remote file on disk, and keeps remotes working offline. + +> [!IMPORTANT] +> This crate is the Rust half of the integration. The host's frontend must also use the [`@module-federation/tauri`](https://www.npmjs.com/package/@module-federation/tauri) runtime plugin, which rewrites remote entries from `http(s)://` to `mf://` so their requests reach this plugin. + +## What you get + +- An `mf://` protocol handler that fetches remote files and caches them in the app cache dir, so the cache survives restarts. +- Remotes that keep loading offline, when a remote answers with an error status, or when it accepts the connection but never answers. +- Automatic rollback to the last version that loaded when a new release of a remote fails to load. + +## Install + +```bash +cargo add tauri-plugin-module-federation +npm install @module-federation/tauri +``` + +## Usage + +Register the plugin with the defaults: + +```rust +tauri::Builder::default() + .plugin(tauri_plugin_module_federation::init(None)) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +``` + +Then add the runtime plugin to the host's Module Federation config, for example with Rsbuild: + +```ts +pluginModuleFederation({ + name: 'host', + remotes: { + remote: 'remote@http://localhost:3002/remoteEntry.js', + }, + runtimePlugins: ['@module-federation/tauri'], +}); +``` + +Webpack and `@module-federation/vite` hosts use the same `runtimePlugins` entry. See the [Vite guide](https://github.com/module-federation/tauri-plugin-module-federation/blob/main/docs/vite.md) for Vite remotes. + +## Configuration + +Use `Builder` to set the cache folder, the timeouts, and rollback: + +```rust +use std::time::Duration; + +tauri::Builder::default() + .plugin( + tauri_plugin_module_federation::Builder::new() + .cache_folder("module-federation") + .connect_timeout(Duration::from_secs(10)) + .read_timeout(Duration::from_secs(10)) + .rollback(true) + .build(), + ) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +``` + +Rollback is on by default in release builds and off in debug builds. + +## Offline behavior + +| Situation | What the app gets | +|---|---| +| Remote reachable, responds 2xx | The fresh response. It replaces the cached copy. | +| Offline, or the remote answers an error status | The cached copy. Error responses are never cached. | +| Remote accepts the connection but does not answer | The cached copy after the read timeout (10 s by default). | +| Not reachable and never cached | A `502`/`504` error that the Module Federation runtime reports as a failed remote. | +| A new release that fails to load | The page reloads with the last version that loaded. That version is kept on later launches. | + +The cache layout and known limitations are in [Offline and failed releases](https://github.com/module-federation/tauri-plugin-module-federation/blob/main/docs/offline-and-rollback.md). How requests flow through both packages is in [Architecture](https://github.com/module-federation/tauri-plugin-module-federation/blob/main/docs/architecture.md). + +## License + +MIT