-
Notifications
You must be signed in to change notification settings - Fork 82
feat: new varFilename option - allow generate additional "var" remoteEntry.js file (#247) #353
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
base: main
Are you sure you want to change the base?
feat: new varFilename option - allow generate additional "var" remoteEntry.js file (#247) #353
Conversation
807ccea to
6dad215
Compare
|
@gioboa @ScriptedAlchemy could you check it out? wdyt? |
| }, | ||
| remoteEntry, | ||
| ssrRemoteEntry: remoteEntry, | ||
| varRemoteEntry, |
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.
@ScriptedAlchemy wdyt about additional varRemoteEntry field in manifest.json?
Or maybe we should generate the second item in manifest.json array. Sry, I couldn't find the manifest specification...
|
|
||
| const isValidName = isValidVarName(name); | ||
|
|
||
| // @TODO: implement publicPath/getPublicPath support |
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.
I don't handle publicPath/getPublicPath here. Should I? I rely on generated remoteEntry.js relative path
| function getScriptUrl() { | ||
| const currentScript = document.currentScript; | ||
| if (!currentScript) { | ||
| console.error("[VarRemoteEntry] ${varFilename} script should be called from sync <script> tag (document.currentScript is undefined)") |
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.
I'm not sure about this logic. Maybe there is another way to indicate path of original remoteEntry.js file?
I've stolen it from __webpack_public_path__ ('auto') implementation...
| const isValidName = isValidVarName(name); | ||
|
|
||
| if (!isValidName) { | ||
| warn( |
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.
Should we fail if provided name is not valid js name?
In this case it's not possible to load this remote entry in old fashion way, it won't work:
remotes: {
'@app/remote': '@app/remote@http://localhost:3000/varRemoteEntry.js',
}But, as my example shows, this still works with dynamic loadRemote, therefore I've decided to handle it with globalThis and showing the warn message
6dad215 to
e8f777f
Compare
Problem
@module-federation/vitegenerates esm onlyremoteEntry.jsfile, thus you are not able to load it in "old fashion way"Problem example:
Solution
We can generate additional
varRemoteEntry.jsfile,This file will just
import()our esmremoteEntry.jsfile and callinit/getmethods. Example:Thus
hostapplication may use it:// host plugins: [ federation({ remotes: { - remote: 'remote@http://localhost:3000/remoteEntry.js' + remote: 'remote@http://localhost:3000/varRemoteEntry.js' }, }), ]Moreover: I've added new property into
manifest.json-varRemoteEntry, I hope it's okay...Current problems
publicPath/getPublicPathoptionsRelated issues: