Skip to content
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

Add documentation / example for including module federation runtime via CDN in browser script tag #2630

Open
2 tasks done
keshavkaul opened this issue Jun 18, 2024 · 4 comments

Comments

@keshavkaul
Copy link

Clear and concise description of the problem

I was looking for a solution to include mf runtime via CDN in a script tag. Did not find any solutions in examples.

Suggested solution

I instead used unpkg.com to create a CDN link for @module-federation/runtime package.
Below is the solution:

<script type="module">
	const {init, loadRemote} = await import('https://unpkg.com/@module-federation/runtime@0.1.20/dist/index.esm.js?module');
            
	console.log("working")
</script>

Request someone to update the docs or examples with this solution.

Alternative

No response

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@ScriptedAlchemy
Copy link
Member

Typically we do not advise this solution, but it should be possible.

You can submit a PR if you have created a sample that seems to work, happy to edit it etc.

@ScriptedAlchemy
Copy link
Member

Are you using module federation via webpack/rspack hosts?
Do you need the runtime externalized within the source code of the remotes so you can access it via external?

@keshavkaul
Copy link
Author

keshavkaul commented Jun 20, 2024

@ScriptedAlchemy We are migrating our current brownfield project written in ASP.NET Framework 4.7 and wanted to incrementally move towards Nextjs UI framework. So we are creating React UI islands in ASP.NET that fetches Module Federated React components at runtime from a Nextjs UI server

@ScriptedAlchemy
Copy link
Member

ScriptedAlchemy commented Jun 21, 2024

I'm not sure if it will work with Next the way you want. Next can be a bit tricky to work with, and depending on what you're exposing, the host may also need to be configured for Next. You could consider using the esm module to load it off a CDN, though. But Next might still pose some challenges.

Load it from esm like you had, then use init and loadRemote. If you use next/link, it wont work. You will need to expose only react components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants