-
Notifications
You must be signed in to change notification settings - Fork 25
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
share-loader #43
Comments
@NishanthRE : the example from this repo only works with Angular < 9. For Angular 9 you have manually manage to get the app-bundle into the window-object (not via LastCallWebpackPlugin in webpack config. For this you can use the following trick (es module import):
This will generate a login-chunk in your dist folder, so your main-chunk gets split into main- and login-chunk, where the login-chunk contains the micro frontend. And the main-chunk will load the login-chunk. So, then you also have to tweak the sLoader to wait for the chunk. You can do sth like this:
|
@MrFrankel/share-loader<mailto:[email protected]>: Thanks for your response. Surely will do these changes in my app and request is can you please update the share loader sample code for angular 9 in your git because it will be usefull many of the peoples.
Thanks,
Nishant
From: Alexej Strelzow <[email protected]>
Sent: 03 May 2020 18:36
To: MrFrankel/share-loader <[email protected]>
Cc: Nishanthkumar M <[email protected]>; Mention <[email protected]>
Subject: Re: [MrFrankel/share-loader] share-loader (#43)
@NishanthRE<https://github.com/NishanthRE> : the example from this repo only works with Angular < 9. For Angular 9 you have manually manage to get the app-bundle into the window-object (not via LastCallWebpackPlugin in webpack config.
For this you can use the following trick (es module import):
import(/* webpackChunkName: "login" */ './app/app.external.module').then(m => {
(window as any)['login'] = {};
(window as any)['login']['appModule'] = m.AppModule;
});
This will generate a login-chunk in your dist folder, so your main-chunk gets split into main- and login-chunk, where the login-chunk contains the micro frontend. And the main-chunk will load the login-chunk.
So, then you also have to tweak the sLoader to wait for the chunk. You can do sth like this:
/**
* Checks in a certain interval if the AppModule is available inside the window object
* in order to hand it over to Angular's loadChildren function (lazy loading).
* @param resolvedScript The micro frontend we are waiting for
*/
private static async waitForMicroFrontendToBeAvailable(resolvedScript: Script) {
while (window[resolvedScript.name]?.[resolvedScript.module] === undefined) {
await new Promise(r => setTimeout(r, 300));
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#43 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AKJDF2XAIKIFJVK3644YUFTRPVT2NANCNFSM4K5YYEMA>.
|
Hello @NishanthRE, Are you able to resolve the issue? If YES, could you please share us the code. I couldn't able to resolve with above provided solution. Any help would be appreciated. |
Also, to resolve this issue you can change "target" from "es2015" to "es5" in tsconfig.json. |
@MrFrankel Firstly your idea with the share-loader was amzing. i have some doubts. i have created a new angular 9 application into the example cli folder and included all your dependencies like extra-webpack config and changed the angular.json as we need. when triggering the build command i have stucked with the following error
`
Generating ES5 bundles for differential loading...
An unhandled exception occurred: f:\Research & Dev\share-loader\example-cli\ext-app2\polyfills-es5.js: Invalid left-hand side in assignment expression (9:2)
7 | exports["polyfills-es5.js"] = factory(polyfills-es5.js);
8 | else
and when i try to load the newly created application from shell app am receiving like this
Can you please help me to get out from this?
The text was updated successfully, but these errors were encountered: