This architecture is an absolute nightmare to work with, but hopefully someone is able to give me a hand. I'm using Angular 13, and @angular-architects/module-federation 14.2.0.
I'll try to give a simplified version of the project I'm working with.
project structure is
↓project-name
↓dist
>project1
>project2
>shell
>shared-library
>node_modules
↓projects
>project1
>project2
>shell
>shared-library
Shell and each project have this in their webpack.config:
sharedMappings.register(
path.join(__dirname, '../../tsconfig.json'),
['@shared-library']
tsconfig.json has this path setup for shared-library
"@shared-library": [
"projects/shared-library/src/public-api.ts"
],
I've seen some random blogs that show the tsconfig.json path using the path to the library in the dist folder instead of public-api.ts. I've tried that, but it does nothing either.
shared-library has a structure like
>shared-library
↓src
>lib
>shared-library.module.ts
>shared-library.service.ts
public-api.ts
shared-library.service.ts has the @Injectable({ providedIn: 'root' }) decorator.
The components that are using shared-library.service are importing it using
import { SharedLibraryService } from '@shared-library';
constructor(private shared-library: SharedLibraryServce) {}
When I run it locally it works fine, the shared-library.service is a singleton and each MFE can share data with it.
When I deploy the project, shared-library is instantiated in the shell and each MFE, so it totally breaks the project.
I'm not really experienced with the deployment part so I'm assuming there's something I'm doing wrong.
angular.json has "baseHref"s for each project in a structure like "/projectName/apps/project1", so when I move the files to the server, I place them in a structure like
all shell files
>apps
>project1
>project2
I've tried placing this library in every possible place and nothing makes a difference, but I also noticed that even if I don't put the library on the server, it still exists and is still being instantiated multiple times, so I guess deploying the library is unnecessary?
There is a lot more to the code than I provided, but I don't know that this type of project can even be done in stackblitz for a more complete example. I tried to give all code that seemed relevant to the problem, but I can give more samples of my code as requested.