Skip to content

feat(modern-js-plugin): add server plugin to handle remote's SSR assets #3777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025

Conversation

zllkjc
Copy link
Contributor

@zllkjc zllkjc commented May 15, 2025

Description

This PR optimizes the use of MF & Modern.js SSR.

For security reasons, the Modern.js server by default only hosts files in the dist/static directory.!6924

While @module-federation/modern-js places SSR output in the bundles/ directory, just like Modern.js SSR output. Therefore, in the past, when deploying to production, developers needed to copy the MF SSR output to the static resource directory and upload it to CDN, otherwise consumers couldn't access the producer.

But in our practice, we found that many developers don't use CDN, but use Modern.js deployment to generate products which can run in Node.js. And developers also can't mock the production environment locally by using Modern.js build + serve commands.

Now the @module-federation/modern-js also provides a server-side plugin for Modern.js, used to host the MF SSR output. Devs only need to run the Modern.js server to access the MF SSR output, whether through Modern.js deployment or when mock the production environment locally.

In this PR, I also upgraded the version of Modern.js. We need to use this feature in versions after 2.67.6.

In addition, I use fs-extra instead of @modern-js/utils, the latter is more like an internal package, and it is not recommended to use it in MF plugin.


ps: If have any questions, feel free to submit an Issue for Modern.js or communicate under this PR.

Related Issue

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Copy link

changeset-bot bot commented May 15, 2025

🦋 Changeset detected

Latest commit: 8cb01eb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 32 packages
Name Type
create-module-federation Patch
@module-federation/devtools Patch
@module-federation/modern-js Patch
@module-federation/modernjsapp Patch
@module-federation/cli Patch
@module-federation/enhanced Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Patch
@module-federation/storybook-addon Patch
remote5 Patch
@module-federation/runtime Patch
@module-federation/rspack Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/dts-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/retry-plugin Patch
@module-federation/data-prefetch Patch
@module-federation/error-codes Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/runtime-core Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch
website-new Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented May 15, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 8cb01eb
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/683441ceb123e30008207a2f
😎 Deploy Preview https://deploy-preview-3777--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@zllkjc zllkjc force-pushed the feat/modern-server-plugin branch from af08207 to e2368d8 Compare May 26, 2025 04:13
@zllkjc zllkjc changed the title WIP feat: add modern server plugin to handle mf ssr product feat(modernjs-plugin): add server plugin to handle remote's SSR assets May 26, 2025
@zllkjc zllkjc changed the title feat(modernjs-plugin): add server plugin to handle remote's SSR assets feat(modernjs-mf): add server plugin to handle remote's SSR assets May 26, 2025
@zllkjc zllkjc changed the title feat(modernjs-mf): add server plugin to handle remote's SSR assets feat(modern-js-plugin): add server plugin to handle remote's SSR assets May 26, 2025
chore: add static file cache

chore: update modernjs version

chore: add unit test for static middleware

chore: imporve pathname logic
@zllkjc zllkjc force-pushed the feat/modern-server-plugin branch from 2c49770 to ed5b57e Compare May 26, 2025 09:38
@2heal1 2heal1 merged commit 0c68c2f into module-federation:main May 27, 2025
14 checks passed
@KyrieLii KyrieLii mentioned this pull request May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants