-
-
Notifications
You must be signed in to change notification settings - Fork 374
feat: initRawContainer method #2011
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
Changes from all commits
43e649b
3fba96e
90e92d5
3a57ef8
5006ebf
8cffe75
a991f2c
06292fa
0dc9c31
9979676
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { FederationRuntimePlugin } from '@module-federation/runtime/types'; | ||
|
|
||
| export default function () { | ||
| return { | ||
| name: 'node-internal-plugin', | ||
| beforeInit(args) { | ||
| const { userOptions } = args; | ||
| if (userOptions.remotes) { | ||
| userOptions.remotes.forEach((remote) => { | ||
| const { alias } = remote; | ||
| if (alias) { | ||
| remote.name = remote.alias; | ||
| } | ||
| }); | ||
| } | ||
| return args; | ||
| }, | ||
| init(args) { | ||
| return args; | ||
| }, | ||
| beforeRequest(args) { | ||
| if (args.id.startsWith('__webpack_require__')) { | ||
| const regex = | ||
| /__webpack_require__\.federation\.instance\.moduleCache\.get\(([^)]+)\)/; | ||
| const match = args.id.match(regex); | ||
| if (match !== null) { | ||
| const req = args.id.replace(match[0], ''); | ||
| const remoteID = match[1].replace(/["']/g, ''); | ||
| args.id = [remoteID, req].join(''); | ||
| } | ||
| } | ||
| return args; | ||
| }, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,6 +482,20 @@ export class FederationHost { | |
| ); | ||
| } | ||
|
|
||
| initRawContainer( | ||
| name: string, | ||
| url: string, | ||
| container: RemoteEntryExports, | ||
| ): Module { | ||
| const remoteInfo = getRemoteInfo({ name, entry: url }); | ||
| const module = new Module({ host: this, remoteInfo }); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @2heal1, could you give me your input on this solution? I believe there are relevant use cases for when a user may sideload a container, and we need a way to convert it to a module instance.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not encounter the case , but I think this solution is okay :D |
||
|
|
||
| module.remoteEntryExports = container; | ||
| this.moduleCache.set(name, module); | ||
|
|
||
| return module; | ||
| } | ||
|
|
||
| private async _getRemoteModuleAndOptions(id: string): Promise<{ | ||
| module: Module; | ||
| moduleOptions: ModuleOptions; | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using script global external modules in Webpack, it searches for containers in the internal module cache, as if it were a global variable.
