Closed msvargas closed 8 months ago
Maybe to help anyone, after research a lot, I found the way, the result:
I know we can improve the implementation but it works, maybes some comment regarding to the correct way to add this it would be great, thanks!
https://github.com/msvargas/microapps-poc/blob/main/WebHost/src/utils/loadComponent.js#L3
repack v3 will bring better support to high level apis, so youll be able to just use import from, like youd do in a normal browser app. Wont be limited to only low-level api like in v2
Hi @ScriptedAlchemy thanks for your answer, when will repack v3 be available? thanks
Should already be on npm as a beta tag
To be precise it's under next
tag: https://www.npmjs.com/package/@callstack/repack
Thanks @zamotany currently I implemented it with yarn v3 and it is awesome! good job and thank you for sharing, I have some issue at the moment but I everything looks good.
@zamotany I have issue with this line: https://github.com/callstack/repack-examples/blob/9be2bf7122c556635125c7282b9fdbb3698119f0/module-federation/app1/webpack.config.mjs#L43 Do you recommend to turn off the fast refresh for module federation? thanks
Hot reloading doesnt work with module federation. It's insanely complex to support HMR since it would require all the modules graphs being aware of eachother and how the remote modules are used be eachother.
If possible, I usually just use live reload for remote changes. So just refresh the page if the remote was updated and only use hmr for the host app parts
Hi guys @ScriptedAlchemy @zamotany, the new API ScriptManager and Federated is awesome, I'm trying to run Repack V3 on web I really appreciate any help or information, I get this error:
Then, I've tried to fixed it, I've created new Webpack Plugin called, RepackWebTargetPlugin, but now I get this error
const {
RepackInitRuntimeModule,
} = require('@callstack/repack/dist/webpack/plugins/RepackTargetPlugin/runtime/RepackInitRuntimeModule');
const {
RepackLoadScriptRuntimeModule,
} = require('@callstack/repack/dist/webpack/plugins/RepackTargetPlugin/runtime/RepackLoadScriptRuntimeModule');
class RepackWebTargetPlugin {
apply(compiler) {
const globalObject = compiler.options.output.globalObject || 'global';
// Normalize global object.
new webpack.BannerPlugin({
raw: true,
entryOnly: true,
banner: webpack.Template.asString([
`/******/ var ${globalObject} = ${globalObject} || this || new Function("return this")() || ({}); // repackGlobal'`,
'/******/',
]),
}).apply(compiler);
compiler.hooks.compilation.tap('RepackTargetPlugin', (compilation) => {
compilation.hooks.additionalTreeRuntimeRequirements.tap('RepackTargetPlugin', (chunk, runtimeRequirements) => {
runtimeRequirements.add(webpack.RuntimeGlobals.startupOnlyAfter);
// Add code initialize Re.Pack's runtime logic.
compilation.addRuntimeModule(
chunk,
new RepackInitRuntimeModule({
chunkId: chunk.id ?? undefined,
globalObject,
chunkLoadingGlobal: compiler.options.output.chunkLoadingGlobal,
hmrEnabled: compilation.options.mode === 'development' && this.config?.hmr,
}),
);
});
// Overwrite Webpack's default load script runtime code with Re.Pack's implementation
// specific to React Native.
compilation.hooks.runtimeRequirementInTree.for(webpack.RuntimeGlobals.loadScript).tap('RepackTargetPlugin', (chunk) => {
compilation.addRuntimeModule(chunk, new RepackLoadScriptRuntimeModule(chunk.id ?? undefined));
// Return `true` to make sure Webpack's default load script runtime is not added.
return true;
});
});
}
}
Thanks
@msvargas RepackWebTargetPlugin
will not fix the problem. ScriptManager
was never intended to runned in the browser, but given that it's used inside source code it would make sense to make it usable on web too.
So, definitely remove RepackWebTargetPlugin
and you'll have to wait for a web-compatible ScriptManager
.
Hey guys, @zamotany, for android the localhost doesn't work, I have to use 10.0.2.2, Is this the expected behavior? Thanks
Yes, localhost
on Android points to the Android device itself. It's expected and we should be more clear about it in the docs.
Thank for your answer @msvargas! I've tried your and @zamotany suggest, I change in Root.js the localhost, but now:
ChunkManager.configure({
forceRemoteChunkResolution: true,
resolveRemoteChunk: async (chunkId, parentId) => {
let url;
switch (parentId) {
case 'app1':
url = `http://10.0.2.2:9000/${chunkId}.chunk.bundle`;
break;
case 'app2':
url = `http://10.0.2.2:9001/${chunkId}.chunk.bundle`;
break;
case 'main':
default:
url =
{
// containers
app1: 'http://10.0.2.2:9000/app1.container.bundle',
app2: 'http://10.0.2.2:9001/app2.container.bundle',
}[chunkId] ?? `http://10.0.2.2:8081/${chunkId}.chunk.bundle`;
break;
}
if I use Android Studio the error is the same:
Am I doing something wrong?
I'm not sure, it is very weird, what repack version are you using?
@callstack/repack 2.5.1
Could it be related to this? https://github.com/callstack/repack/issues/138 (the solution doesn't work for me)
It happens when building app1 on first launch, is it perhaps the loading wait time too long that generates the error?
How to build release file(apk)
Hello @msvargas , this is exciting - to include two isolated react-native apps into a container react-native app; Can you please do a tutorial video on how you achieved this? or quote a reference material?
Hello @msvargas , this is exciting - to include two isolated react-native apps into a container react-native app; Can you please do a tutorial video on how you achieved this? or quote a reference material?
Hi, Have you already check this video? https://youtu.be/2DEoB7Vylqo
This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.
This issue has been automatically closed because it has been inactive for more than 14 days. Please reopen if you want to add more context.
Hi,
I want to know if it is possible to reuse the same code on web and mobile (iOS,Android) using react-native-web + Module Federation and what is the best approach or implementation, maybe some example, I really appreciate it!
thank you very much