feat(vite-plugin-zephyr): decouple module federation integration#409
feat(vite-plugin-zephyr): decouple module federation integration#409
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors vite-plugin-zephyr to make withZephyr() the primary public API while supporting a separately configured @module-federation/vite plugin by detecting it, ensuring the Zephyr runtime plugin is injected, and serving that runtime plugin via a Zephyr virtual module.
Changes:
- Refactors
withZephyr()to (optionally) delegate to@module-federation/vitewhile keeping Zephyr’s core Vite integration in a separate internal plugin. - Adds runtime-plugin injection utilities and tests; improves MF plugin extraction to handle nested plugin arrays.
- Updates Module Federation dependency versions and adjusts the Vite MF example/README to use
plugins: [react(), federation(mfConfig), withZephyr()].
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | Bumps MF catalog versions (@module-federation/runtime, @module-federation/vite). |
| pnpm-lock.yaml | Lockfile updates for the MF version bumps and related transitive deps. |
| libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts | Main refactor: MF plugin detection, runtime plugin virtual module, and new withZephyr() composition. |
| libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.spec.ts | Adds unit tests for withZephyr() behavior with/without mfConfig. |
| libs/vite-plugin-zephyr/src/lib/types/module-federation-options.ts | Introduces exported MF options type alias derived from @module-federation/vite. |
| libs/vite-plugin-zephyr/src/lib/internal/mf-vite-etl/ensure_runtime_plugin.ts | Adds helper to inject the Zephyr MF runtime plugin and resolve its runtime source path/IDs. |
| libs/vite-plugin-zephyr/src/lib/internal/mf-vite-etl/test/ensure_runtime_plugin.test.ts | Tests for runtime plugin injection/deduplication. |
| libs/vite-plugin-zephyr/src/lib/internal/extract/extract_mf_plugin.ts | Enhances MF plugin detection by flattening nested plugin arrays and loosening input typing. |
| libs/vite-plugin-zephyr/src/index.ts | Adjusts exports to keep withZephyr() as the API and re-exports MF options type from the new file. |
| libs/vite-plugin-zephyr/package.json | Moves MF Vite to optional peer + devDependency (decoupling runtime dependency). |
| libs/vite-plugin-zephyr/README.md | Updates docs to show configuring MF plugin separately and installing MF only when needed. |
| examples/vite-react-mf/remote/vite.config.ts | Updates example to explicitly add federation(mfConfig) and then withZephyr(). |
| examples/vite-react-mf/remote/package.json | Adds @module-federation/vite to devDependencies for the example. |
| examples/vite-react-mf/host/vite.config.ts | Updates example to explicitly add federation(mfConfig) and then withZephyr(). |
| examples/vite-react-mf/host/package.json | Adds @module-federation/vite to devDependencies for the example. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
arthurfiorette
left a comment
There was a problem hiding this comment.
late night review from my phone :)
What's added in this PR?
This refactors
vite-plugin-zephyrsowithZephyr()is the single public API while still supporting external@module-federation/viteconfiguration. The plugin now detects an existing MF Vite plugin, injects the Zephyr runtime plugin early, and serves that runtime plugin through a Zephyr virtual module so remote rewrites still happen without Zephyr wrapping federation directly.It also removes the temporary split public APIs, updates the Vite MF example to use
plugins: [react(), federation(mfConfig), withZephyr()], and upgrades the MF Vite/runtime versions so the examples can use normal ESM imports.Screenshots
N/A
What's the issues or discussion related to this PR ?
The Vite integration had grown a hard dependency on Zephyr wrapping the Module Federation plugin. That made the API inconsistent with the other Zephyr plugins and blocked using
withZephyr()alongside a separately configuredfederation(mfConfig). The goal here is to keep the rewrites and deployment behavior while removing the extra public wrapper API.What are the steps to test this PR?
pnpm installpnpm nx test vite-plugin-zephyrpnpm nx build vite-plugin-zephyrpnpm --filter vite-host run buildpnpm --filter vite-remote run buildDocumentation update for this PR (if applicable)?
Updated the package README in this repo. No separate zephyr-documentation PR.
(Optional) What's left to be done for this PR?
(Optional) What's the potential risk and how to mitigate it?
module-federation-viteplugin exposing_options. If upstream changes that internal shape, the Zephyr injection path could regress.(Required) Pre-PR/Merge checklist