├── .idea ├── .gitignore ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── multi-framework-module-federation.iml └── vcs.xml ├── README.md ├── angular-mfe1 ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.less │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── components │ │ │ └── welcome │ │ │ │ ├── welcome.component.html │ │ │ │ ├── welcome.component.less │ │ │ │ ├── welcome.component.spec.ts │ │ │ │ └── welcome.component.ts │ │ └── modules │ │ │ └── business-module │ │ │ ├── business-routing.module.ts │ │ │ ├── business.module.ts │ │ │ ├── business │ │ │ ├── business.component.html │ │ │ ├── business.component.less │ │ │ ├── business.component.spec.ts │ │ │ └── business.component.ts │ │ │ ├── models │ │ │ ├── event-bus.service.d.ts │ │ │ ├── navigation.const.ts │ │ │ ├── navigation.service.d.ts │ │ │ └── note.model.ts │ │ │ ├── notes.service.spec.ts │ │ │ └── notes.service.ts │ ├── assets │ │ └── .gitkeep │ ├── bootstrap.ts │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.less │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json ├── webpack.config.js ├── webpack.prod.config.js └── yarn.lock ├── angular-mfe2 ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.less │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── components │ │ │ └── welcome │ │ │ │ ├── welcome.component.html │ │ │ │ ├── welcome.component.less │ │ │ │ ├── welcome.component.spec.ts │ │ │ │ └── welcome.component.ts │ │ └── modules │ │ │ └── notes-counter │ │ │ ├── models │ │ │ ├── event-bus.service.d.ts │ │ │ └── note.model.ts │ │ │ ├── notes-counter-routing.module.ts │ │ │ ├── notes-counter.module.ts │ │ │ ├── notes-counter │ │ │ ├── notes-counter.component.html │ │ │ ├── notes-counter.component.less │ │ │ ├── notes-counter.component.spec.ts │ │ │ └── notes-counter.component.ts │ │ │ └── services │ │ │ └── notes.service.ts │ ├── assets │ │ └── .gitkeep │ ├── bootstrap.ts │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.less │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json ├── webpack.config.js ├── webpack.prod.config.js └── yarn.lock ├── angular-mfe3 ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.less │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── components │ │ │ └── welcome │ │ │ │ ├── welcome.component.html │ │ │ │ ├── welcome.component.less │ │ │ │ ├── welcome.component.spec.ts │ │ │ │ └── welcome.component.ts │ │ └── modules │ │ │ └── notes-counter │ │ │ ├── models │ │ │ ├── event-bus.service.d.ts │ │ │ └── note.model.ts │ │ │ ├── notes-counter-routing.module.ts │ │ │ ├── notes-counter.module.ts │ │ │ ├── notes-counter │ │ │ ├── notes-counter.component.html │ │ │ ├── notes-counter.component.less │ │ │ ├── notes-counter.component.spec.ts │ │ │ └── notes-counter.component.ts │ │ │ └── services │ │ │ └── notes.service.ts │ ├── assets │ │ └── .gitkeep │ ├── bootstrap.ts │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.less │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json ├── webpack.config.js └── webpack.prod.config.js ├── angular-shell ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package.json ├── sampleConfiguration.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.less │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── app.service.ts │ │ ├── components │ │ │ ├── angular-wrapper │ │ │ │ └── angular-wrapper.component.ts │ │ │ ├── self-run-wrapper │ │ │ │ └── self-run-wrapper.component.ts │ │ │ ├── vue-wrapper │ │ │ │ └── vue-wrapper.component.ts │ │ │ └── welcome │ │ │ │ ├── welcome.component.html │ │ │ │ ├── welcome.component.less │ │ │ │ ├── welcome.component.spec.ts │ │ │ │ └── welcome.component.ts │ │ ├── microfrontends │ │ │ ├── event-bus.service.ts │ │ │ ├── federation-plugin.service.ts │ │ │ ├── global-navigation.service.ts │ │ │ ├── microfrontend.model.ts │ │ │ ├── navigation.const.ts │ │ │ └── sample-configuration.ts │ │ ├── modules │ │ │ └── react-wrapper │ │ │ │ ├── components │ │ │ │ └── react-wrapper │ │ │ │ │ └── react-wrapper.component.tsx │ │ │ │ ├── react-wrapper.module.ts │ │ │ │ └── react-wrapper.routes.ts │ │ └── utils │ │ │ ├── federation-utils.ts │ │ │ └── route-utils.ts │ ├── assets │ │ └── .gitkeep │ ├── bootstrap.ts │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.less │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json ├── webpack.config.js ├── webpack.prod.config.js └── yarn.lock ├── multi-framework-module-federation.iml ├── package.json ├── react-mfe1 ├── .editorconfig ├── .gitignore ├── .htaccess ├── .prettierrc ├── README.md ├── generate-react-cli.json ├── package.json ├── semantic.json ├── src │ ├── app │ │ ├── components │ │ │ └── notes-list.tsx │ │ ├── index.less │ │ ├── index.tsx │ │ └── models │ │ │ ├── event-bus.model.ts │ │ │ ├── global-navigation.model.ts │ │ │ ├── navigation.const.ts │ │ │ └── note.model.ts │ ├── application.service.ts │ ├── application.tsx │ ├── assets │ │ └── index.html │ ├── main.plugin.js │ ├── main.tsx │ └── sitemap-builder.js ├── tsconfig.json ├── types │ ├── global.d.ts │ └── react-redux.d.ts ├── webpack.config.js └── yarn.lock ├── react-mfe2 ├── .editorconfig ├── .gitignore ├── .prettierrc ├── README.md ├── generate-react-cli.json ├── package.json ├── src │ ├── app │ │ ├── components │ │ │ └── props-plugin │ │ │ │ └── props.component.tsx │ │ ├── containers │ │ │ ├── first-route │ │ │ │ ├── about-container.less │ │ │ │ └── about-container.tsx │ │ │ ├── main-container │ │ │ │ ├── main-container.less │ │ │ │ └── main-container.tsx │ │ │ └── second-component │ │ │ │ ├── contacts-container.less │ │ │ │ └── contacts-container.tsx │ │ ├── index.less │ │ ├── index.tsx │ │ ├── main-styles │ │ │ ├── colors.less │ │ │ ├── main.less │ │ │ └── variables.less │ │ └── routes.ts │ ├── assets │ │ └── index.html │ ├── main.plugin.js │ ├── main.tsx │ ├── props.plugin.js │ └── sitemap-builder.js ├── tsconfig.json ├── types │ └── global.d.ts ├── webpack.config.js └── yarn.lock ├── vue-mfe1 ├── index.html ├── package.json ├── src │ ├── App.vue │ ├── bootstrapFunction.js │ ├── components │ │ ├── Button.js │ │ ├── Content.vue │ │ ├── User.vue │ │ ├── UserPosts.vue │ │ └── UserProfile.vue │ ├── logo.png │ └── main.js ├── webpack.config.js └── yarn.lock └── yarn.lock /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/multi-framework-module-federation.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /angular-mfe1/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /angular-mfe1/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /angular-mfe1/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /angular-mfe1/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /angular-mfe1/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { browser, logging } from 'protractor'; 2 | import { AppPage } from './app.po'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('angular-mfe1 app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /angular-mfe1/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-mfe1/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular-mfe1/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/angular-mfe1'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular-mfe1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-mfe1", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:prod": "ng serve --prod", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "run:all": "node node_modules/@angular-architects/module-federation/src/server/mf-dev-server.js" 13 | }, 14 | "private": true, 15 | "resolutions": { 16 | "webpack": "^5.0.0" 17 | }, 18 | "dependencies": { 19 | "@angular-architects/module-federation": "12.1.1", 20 | "@angular/animations": "~11.2.10", 21 | "@angular/common": "~11.2.10", 22 | "@angular/compiler": "~11.2.10", 23 | "@angular/core": "~11.2.10", 24 | "@angular/forms": "~11.2.10", 25 | "@angular/localize": "~11.2.10", 26 | "@angular/platform-browser": "~11.2.10", 27 | "@angular/platform-browser-dynamic": "~11.2.10", 28 | "@angular/router": "~11.2.10", 29 | "bootstrap": "^5.0.1", 30 | "rxjs": "~6.6.0", 31 | "tslib": "^2.0.0", 32 | "zone.js": "~0.11.3" 33 | }, 34 | "devDependencies": { 35 | "@angular-devkit/build-angular": "~0.1102.9", 36 | "@angular/cli": "~11.2.9", 37 | "@angular/compiler-cli": "~11.2.10", 38 | "@types/jasmine": "~3.6.0", 39 | "@types/node": "^12.11.1", 40 | "codelyzer": "^6.0.0", 41 | "jasmine-core": "~3.6.0", 42 | "jasmine-spec-reporter": "~5.0.0", 43 | "karma": "~6.1.0", 44 | "karma-chrome-launcher": "~3.1.0", 45 | "karma-coverage": "~2.0.3", 46 | "karma-jasmine": "~4.0.0", 47 | "karma-jasmine-html-reporter": "^1.5.0", 48 | "ng-packagr": "11.0.3", 49 | "ngx-build-plus": "10.1.1", 50 | "protractor": "~7.0.0", 51 | "ts-node": "~8.3.0", 52 | "tslint": "~6.1.0", 53 | "typescript": "~4.1.5" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule, Routes} from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { 6 | path: 'business', 7 | loadChildren: () => import('./modules/business-module/business.module').then((module) => module.BusinessModule), 8 | }, 9 | { 10 | path: '', 11 | pathMatch: 'full', 12 | redirectTo: 'business' 13 | } 14 | ]; 15 | 16 | @NgModule({ 17 | imports: [RouterModule.forRoot(routes)], 18 | exports: [RouterModule] 19 | }) 20 | export class AppRoutingModule { 21 | } 22 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 25 | 26 |
27 | 28 |
29 |
30 |
31 |
32 |
33 | 34 |
35 | 36 | 37 |
38 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/app.component.less: -------------------------------------------------------------------------------- 1 | .app-component { 2 | &__header { 3 | > ul { 4 | display: flex; 5 | list-style: none; 6 | background: #84b3ef; 7 | height: 40px; 8 | align-items: center; 9 | color: white; 10 | margin: 0; 11 | 12 | li { 13 | margin: 0 8px; 14 | cursor: pointer; 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular-mfe1'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('angular-mfe1'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('angular-mfe1 app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import {ActivatedRoute} from "@angular/router"; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.less'] 8 | }) 9 | export class AppComponent { 10 | } 11 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {BrowserModule} from '@angular/platform-browser'; 3 | 4 | import {AppRoutingModule} from './app-routing.module'; 5 | import {AppComponent} from './app.component'; 6 | import {WelcomeComponent} from './components/welcome/welcome.component'; 7 | import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent, 12 | WelcomeComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | BrowserAnimationsModule, 17 | AppRoutingModule 18 | ], 19 | bootstrap: [AppComponent] 20 | }) 21 | export class AppModule { 22 | } 23 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/components/welcome/welcome.component.html: -------------------------------------------------------------------------------- 1 |

This is a simple application to expose example angular module as microfrontend to another application

2 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/components/welcome/welcome.component.less: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe1/src/app/components/welcome/welcome.component.less -------------------------------------------------------------------------------- /angular-mfe1/src/app/components/welcome/welcome.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { WelcomeComponent } from './welcome.component'; 4 | 5 | describe('WelcomeComponent', () => { 6 | let component: WelcomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ WelcomeComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(WelcomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/components/welcome/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-welcome', 5 | templateUrl: './welcome.component.html', 6 | styleUrls: ['./welcome.component.less'] 7 | }) 8 | export class WelcomeComponent { 9 | } 10 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/business-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {RouterModule, Routes} from '@angular/router'; 4 | import {BusinessComponent} from './business/business.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: 'notesPlugin', 9 | component: BusinessComponent, 10 | }, 11 | { 12 | path: 'reactShop', 13 | component: BusinessComponent, 14 | }, 15 | 16 | { 17 | path: '', 18 | pathMatch: 'full', 19 | redirectTo: 'notesPlugin' 20 | } 21 | ]; 22 | 23 | @NgModule({ 24 | declarations: [], 25 | imports: [ 26 | CommonModule, 27 | RouterModule.forChild(routes) 28 | ] 29 | }) 30 | export class BusinessRoutingModule { 31 | } 32 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/business.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {BusinessComponent} from './business/business.component'; 4 | import {BusinessRoutingModule} from './business-routing.module'; 5 | import {ReactiveFormsModule} from '@angular/forms'; 6 | import {NotesService} from './notes.service'; 7 | import {RouterModule} from '@angular/router'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | BusinessComponent 12 | ], 13 | exports: [ 14 | BusinessComponent 15 | ], 16 | imports: [ 17 | CommonModule, 18 | BusinessRoutingModule, 19 | ReactiveFormsModule, 20 | RouterModule, 21 | ], 22 | providers: [ 23 | NotesService 24 | ] 25 | }) 26 | export class BusinessModule { 27 | } 28 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/business/business.component.html: -------------------------------------------------------------------------------- 1 |
2 |

This is a sample notes functionality without ability to delete items.

3 |
To delete items please navigate to
4 |
5 |
6 |
9 |
10 | 11 | 20 |
21 |
22 | 23 | 29 |
30 |
31 | 32 | 38 |
39 | 40 | 41 |
42 |
43 |
44 | 45 |
48 |
49 |
50 |
Type
51 | {{note.type}} 52 |
53 |
54 |
Subject
55 | {{note.subject}} 56 |
57 |
58 |
Body
59 | {{note.body}} 60 |
61 |
62 |
63 |
64 |
65 |
66 | 67 |
68 | 69 | 70 |
71 | No one note is created 72 |
73 |
74 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/business/business.component.less: -------------------------------------------------------------------------------- 1 | @import (inline) "../../../../../node_modules/bootstrap/dist/css/bootstrap.min.css"; 2 | 3 | .business-component { 4 | 5 | padding: 24px; 6 | 7 | &__note { 8 | margin: 16px; 9 | background: white; 10 | padding: 16px; 11 | border-radius: 8px; 12 | box-shadow: 0 0 5px #ccc; 13 | } 14 | 15 | &__empty { 16 | padding: 24px; 17 | text-align: center; 18 | color: #5d5d5d; 19 | font-size: 22px; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/business/business.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BusinessComponent } from './business.component'; 4 | 5 | describe('BusinessComponent', () => { 6 | let component: BusinessComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ BusinessComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BusinessComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/business/business.component.ts: -------------------------------------------------------------------------------- 1 | import {AfterContentInit, Component, Inject, Optional, ViewEncapsulation} from '@angular/core'; 2 | import {NotesService} from '../notes.service'; 3 | import {FormBuilder, FormGroup, Validators} from '@angular/forms'; 4 | import {Note} from '../models/note.model'; 5 | import {EventBusService} from '../models/event-bus.service'; 6 | import {Router} from '@angular/router'; 7 | import {NavigationAlias} from '../models/navigation.const'; 8 | import {GlobalNavigationService} from '../models/navigation.service'; 9 | 10 | @Component({ 11 | selector: 'app-business-1', 12 | templateUrl: './business.component.html', 13 | styleUrls: ['./business.component.less'], 14 | encapsulation: ViewEncapsulation.None 15 | }) 16 | export class BusinessComponent implements AfterContentInit { 17 | 18 | public formGroup: FormGroup; 19 | public notes: Array = []; 20 | 21 | constructor(private notesService: NotesService, 22 | private formBuilder: FormBuilder, 23 | private router: Router, 24 | @Optional() @Inject('GLOBAL_EVENT_BUS') private pluginEventBus: EventBusService, 25 | @Optional() @Inject('GLOBAL_NAVIGATION_SERVICE') private globalNavigationService: GlobalNavigationService 26 | ) { 27 | this.formGroup = this.formBuilder.group({ 28 | type: [null], 29 | subject: [null, Validators.required], 30 | body: [null] 31 | }); 32 | 33 | } 34 | 35 | ngAfterContentInit(): void { 36 | this.notes = this.notesService.getAllNotes(); 37 | this.notesService.postNotesCountMessage(this.notes?.length); 38 | } 39 | 40 | public saveNote(): void { 41 | this.notesService.saveNote(this.formGroup.value); 42 | this.notes.unshift(this.formGroup.value); 43 | this.notesService.postNotesCountMessage(this.notes?.length); 44 | } 45 | 46 | public _navigateToAdminTool(): void { 47 | this.globalNavigationService?.navigate(NavigationAlias.NOTES_ADMIN_PANEL); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/models/event-bus.service.d.ts: -------------------------------------------------------------------------------- 1 | export type EventBusService = { 2 | readonly name: string; 3 | onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 4 | onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 5 | /** 6 | * Closes the BroadcastChannel object, opening it up to garbage collection. 7 | */ 8 | close(): void; 9 | /** 10 | * Sends the given message to other BroadcastChannel objects set up for this channel. Messages can be structured objects, e.g. nested objects and arrays. 11 | */ 12 | postMessage(message: any): void; 13 | addEventListener(type: string, listener: (this: BroadcastChannel, ev: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void; 14 | removeEventListener(type: K, listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, options?: boolean | EventListenerOptions): void; 15 | removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; 16 | } 17 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/models/navigation.const.ts: -------------------------------------------------------------------------------- 1 | // TODO: move to lib 2 | export enum NavigationAlias { 3 | NOTES_ADMIN_PANEL = 'NOTES_ADMIN_PANEL', 4 | NOTES_LIST = 'NOTES_LIST' 5 | } 6 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/models/navigation.service.d.ts: -------------------------------------------------------------------------------- 1 | import {NavigationAlias} from './navigation.const'; 2 | 3 | export type GlobalNavigationService = { 4 | navigate(routeAlias: NavigationAlias): void; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/models/note.model.ts: -------------------------------------------------------------------------------- 1 | export type Note = { 2 | id: string; 3 | subject: string; 4 | body: string; 5 | type: string; 6 | } 7 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/notes.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { NotesService } from './notes.service'; 4 | 5 | describe('NotesService', () => { 6 | let service: NotesService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(NotesService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /angular-mfe1/src/app/modules/business-module/notes.service.ts: -------------------------------------------------------------------------------- 1 | import {Inject, Injectable, Optional} from '@angular/core'; 2 | import {Observable, of} from 'rxjs'; 3 | import {Note} from './models/note.model'; 4 | import {EventBusService} from './models/event-bus.service'; 5 | 6 | @Injectable() 7 | export class NotesService { 8 | constructor(@Optional() @Inject('GLOBAL_EVENT_BUS') private pluginEventBus: EventBusService) { 9 | } 10 | 11 | public saveNote(note: Note): Observable { 12 | let existingNotes: Array; 13 | const existingNotesString: string | null = window.localStorage.getItem('my_notes'); 14 | if (!existingNotesString) { 15 | existingNotes = []; 16 | } else { 17 | existingNotes = JSON.parse(existingNotesString); 18 | } 19 | 20 | existingNotes.push(note); 21 | this.pluginEventBus?.postMessage({name: 'AddNoteEvent', payload: note}); 22 | return of(window.localStorage.setItem('my_notes', JSON.stringify(existingNotes))); 23 | } 24 | 25 | public getAllNotes(): Array { 26 | let existingNotes: Array; 27 | const existingNotesString: string | null = window.localStorage.getItem('my_notes'); 28 | if (!existingNotesString) { 29 | existingNotes = []; 30 | } else { 31 | existingNotes = JSON.parse(existingNotesString); 32 | } 33 | return existingNotes; 34 | } 35 | 36 | public postNotesCountMessage(count: number): void { 37 | this.pluginEventBus?.postMessage({name: 'NotesCountUpdate', payload: {count}}); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /angular-mfe1/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe1/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-mfe1/src/bootstrap.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-mfe1/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-mfe1/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-mfe1/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe1/src/favicon.ico -------------------------------------------------------------------------------- /angular-mfe1/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularMfe1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /angular-mfe1/src/main.ts: -------------------------------------------------------------------------------- 1 | import('./bootstrap') 2 | .catch(err => console.error(err)); 3 | -------------------------------------------------------------------------------- /angular-mfe1/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * IE11 requires the following for NgClass support on SVG elements 23 | */ 24 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 25 | 26 | /** 27 | * Web Animations `@angular/platform-browser/animations` 28 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 29 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 30 | */ 31 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 32 | 33 | /** 34 | * By default, zone.js will patch all possible macroTask and DomEvents 35 | * user can disable parts of macroTask/DomEvents patch by setting following flags 36 | * because those flags need to be set before `zone.js` being loaded, and webpack 37 | * will put import in the top of bundle, so user need to create a separate file 38 | * in this directory (for example: zone-flags.ts), and put the following flags 39 | * into that file, and then add the following code before importing zone.js. 40 | * import './zone-flags'; 41 | * 42 | * The flags allowed in zone-flags.ts are listed here. 43 | * 44 | * The following flags will work for all browsers. 45 | * 46 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 47 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 48 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 49 | * 50 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 51 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 52 | * 53 | * (window as any).__Zone_enable_cross_context_check = true; 54 | * 55 | */ 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by default for Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | /*************************************************************************************************** 64 | * APPLICATION IMPORTS 65 | */ 66 | -------------------------------------------------------------------------------- /angular-mfe1/src/styles.less: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | //@import (inline) "../node_modules/bootstrap/dist/css/bootstrap.min.css"; 3 | -------------------------------------------------------------------------------- /angular-mfe1/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /angular-mfe1/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /angular-mfe1/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "es2015", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ] 23 | }, 24 | "angularCompilerOptions": { 25 | "enableI18nLegacyMessageIdFormat": false, 26 | "strictInjectionParameters": true, 27 | "strictInputAccessModifiers": true, 28 | "strictTemplates": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /angular-mfe1/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-mfe1/webpack.config.js: -------------------------------------------------------------------------------- 1 | const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); 2 | const mf = require("@angular-architects/module-federation/webpack"); 3 | const path = require("path"); 4 | const dependencies = require("./package.json").dependencies; 5 | 6 | const sharedMappings = new mf.SharedMappings(); 7 | sharedMappings.register( 8 | path.join(__dirname, 'tsconfig.json'), 9 | [/* mapped paths to share */]); 10 | 11 | module.exports = { 12 | output: { 13 | uniqueName: "angular_mfe_1", 14 | publicPath: "auto" 15 | }, 16 | module: { 17 | rules: [ 18 | { 19 | test: /\.css$/i, 20 | use: ["style-loader", "css-loader"], 21 | } 22 | ] 23 | }, 24 | optimization: { 25 | runtimeChunk: false 26 | }, 27 | resolve: { 28 | alias: { 29 | ...sharedMappings.getAliases(), 30 | } 31 | }, 32 | plugins: [ 33 | new ModuleFederationPlugin({ 34 | name: "angular_mfe_1", 35 | library: {type: "var", name: "angular_mfe_1"}, 36 | filename: "remoteEntry.js", 37 | exposes: { 38 | MfeModule: "./src/app/modules/business-module/business.module.ts", 39 | BusinessComponent: "./src/app/modules/business-module/business/business.component.ts" 40 | }, 41 | shared: { 42 | '@angular/common/http': { 43 | version: dependencies['@angular/common'], 44 | requiredVersion: dependencies['@angular/common'], 45 | singleton: true, 46 | 47 | }, 48 | '@angular/common': { 49 | version: dependencies['@angular/common'], 50 | requiredVersion: dependencies['@angular/common'], 51 | singleton: true, 52 | 53 | }, 54 | '@angular/core': { 55 | version: dependencies['@angular/core'], 56 | requiredVersion: dependencies['@angular/core'], 57 | singleton: true, 58 | 59 | }, 60 | '@angular/platform-browser': { 61 | version: dependencies['@angular/platform-browser'], 62 | requiredVersion: dependencies['@angular/platform-browser'], 63 | singleton: true, 64 | 65 | }, 66 | '@angular/platform-browser-dynamic': { 67 | version: dependencies['@angular/platform-browser-dynamic'], 68 | requiredVersion: dependencies['@angular/platform-browser-dynamic'], 69 | singleton: true, 70 | 71 | }, 72 | '@angular/router': { 73 | version: dependencies['@angular/router'], 74 | requiredVersion: dependencies['@angular/router'], 75 | singleton: true, 76 | 77 | }, 78 | '@angular/cdk/a11y': { 79 | version: dependencies['@angular/cdk/a11y'], 80 | requiredVersion: dependencies['@angular/cdk/a11y'], 81 | singleton: true, 82 | 83 | }, 84 | '@angular/animations': { 85 | version: dependencies['@angular/animations'], 86 | requiredVersion: dependencies['@angular/animations'], 87 | singleton: true, 88 | 89 | } 90 | } 91 | 92 | }), 93 | ], 94 | }; 95 | -------------------------------------------------------------------------------- /angular-mfe1/webpack.prod.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./webpack.config'); 2 | -------------------------------------------------------------------------------- /angular-mfe2/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /angular-mfe2/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /angular-mfe2/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /angular-mfe2/README.md: -------------------------------------------------------------------------------- 1 | # AngularMfe2 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.2.9. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /angular-mfe2/angular.json: -------------------------------------------------------------------------------- 1 | {"$schema":"./node_modules/@angular/cli/lib/config/schema.json","version":1,"newProjectRoot":"projects","cli":{"packageManager":"yarn"},"projects":{"angular-mfe2":{"projectType":"application","schematics":{"@schematics/angular:component":{"style":"less"},"@schematics/angular:application":{"strict":true}},"root":"","sourceRoot":"src","prefix":"app","architect":{"build":{"builder":"ngx-build-plus:browser","options":{"outputPath":"dist/angular-mfe2","index":"src/index.html","main":"src/main.ts","polyfills":"src/polyfills.ts","tsConfig":"tsconfig.app.json","aot":true,"assets":["src/favicon.ico","src/assets"],"styles":["src/styles.less"],"scripts":[],"extraWebpackConfig":"webpack.config.js","commonChunk":false},"configurations":{"production":{"fileReplacements":[{"replace":"src/environments/environment.ts","with":"src/environments/environment.prod.ts"}],"optimization":true,"outputHashing":"all","sourceMap":false,"namedChunks":false,"extractLicenses":true,"vendorChunk":false,"buildOptimizer":true,"budgets":[{"type":"initial","maximumWarning":"500kb","maximumError":"1mb"},{"type":"anyComponentStyle","maximumWarning":"2kb","maximumError":"4kb"}],"extraWebpackConfig":"webpack.prod.config.js"}}},"serve":{"builder":"ngx-build-plus:dev-server","options":{"browserTarget":"angular-mfe2:build","extraWebpackConfig":"webpack.config.js","port":4202},"configurations":{"production":{"browserTarget":"angular-mfe2:build:production","extraWebpackConfig":"webpack.prod.config.js"}}},"extract-i18n":{"builder":"@angular-devkit/build-angular:extract-i18n","options":{"browserTarget":"angular-mfe2:build"}},"test":{"builder":"ngx-build-plus:karma","options":{"main":"src/test.ts","polyfills":"src/polyfills.ts","tsConfig":"tsconfig.spec.json","karmaConfig":"karma.conf.js","assets":["src/favicon.ico","src/assets"],"styles":["src/styles.less"],"scripts":[],"extraWebpackConfig":"webpack.config.js"}},"lint":{"builder":"@angular-devkit/build-angular:tslint","options":{"tsConfig":["tsconfig.app.json","tsconfig.spec.json","e2e/tsconfig.json"],"exclude":["**/node_modules/**"]}},"e2e":{"builder":"@angular-devkit/build-angular:protractor","options":{"protractorConfig":"e2e/protractor.conf.js","devServerTarget":"angular-mfe2:serve"},"configurations":{"production":{"devServerTarget":"angular-mfe2:serve:production"}}}}}},"defaultProject":"angular-mfe2"} -------------------------------------------------------------------------------- /angular-mfe2/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /angular-mfe2/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { browser, logging } from 'protractor'; 2 | import { AppPage } from './app.po'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('angular-mfe2 app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /angular-mfe2/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-mfe2/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular-mfe2/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/angular-mfe2'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular-mfe2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-mfe2", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:prod": "ng serve --prod", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "run:all": "node node_modules/@angular-architects/module-federation/src/server/mf-dev-server.js" 13 | }, 14 | "private": true, 15 | "resolutions": { 16 | "webpack": "^5.0.0" 17 | }, 18 | "dependencies": { 19 | "@angular-architects/module-federation": "12.1.1", 20 | "@angular/animations": "11.2.10", 21 | "@angular/common": "11.2.10", 22 | "@angular/compiler": "11.2.10", 23 | "@angular/core": "11.2.10", 24 | "@angular/forms": "11.2.10", 25 | "@angular/platform-browser": "11.2.10", 26 | "@angular/platform-browser-dynamic": "11.2.10", 27 | "@angular/router": "11.2.10", 28 | "rxjs": "~6.6.0", 29 | "tslib": "^2.0.0", 30 | "zone.js": "~0.11.3" 31 | }, 32 | "devDependencies": { 33 | "@angular-devkit/build-angular": "~0.1102.9", 34 | "@angular/cli": "~11.2.9", 35 | "@angular/compiler-cli": "11.2.10", 36 | "@types/jasmine": "~3.6.0", 37 | "@types/node": "^12.11.1", 38 | "codelyzer": "^6.0.0", 39 | "jasmine-core": "~3.6.0", 40 | "jasmine-spec-reporter": "~5.0.0", 41 | "karma": "~6.1.0", 42 | "karma-chrome-launcher": "~3.1.0", 43 | "karma-coverage": "~2.0.3", 44 | "karma-jasmine": "~4.0.0", 45 | "karma-jasmine-html-reporter": "^1.5.0", 46 | "ng-packagr": "11.0.3", 47 | "ngx-build-plus": "10.1.1", 48 | "protractor": "~7.0.0", 49 | "ts-node": "~8.3.0", 50 | "tslint": "~6.1.0", 51 | "typescript": "~4.1.5" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule, Routes} from '@angular/router'; 3 | import {WelcomeComponent} from "./components/welcome/welcome.component"; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: 'business', 8 | loadChildren: () => import('./modules/notes-counter/notes-counter.module').then((module) => module.NotesCounterModule), 9 | }, 10 | { 11 | path: '', 12 | pathMatch: 'full', 13 | component: WelcomeComponent 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forRoot(routes)], 19 | exports: [RouterModule] 20 | }) 21 | export class AppRoutingModule { 22 | } 23 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/app.component.less: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe2/src/app/app.component.less -------------------------------------------------------------------------------- /angular-mfe2/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular-mfe2'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('angular-mfe2'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('angular-mfe2 app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.less'] 7 | }) 8 | export class AppComponent { 9 | title = 'angular-mfe2'; 10 | } 11 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | 7 | @NgModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | imports: [ 12 | BrowserModule, 13 | AppRoutingModule 14 | ], 15 | providers: [], 16 | bootstrap: [AppComponent] 17 | }) 18 | export class AppModule { } 19 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/components/welcome/welcome.component.html: -------------------------------------------------------------------------------- 1 |

welcome works!

2 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/components/welcome/welcome.component.less: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe2/src/app/components/welcome/welcome.component.less -------------------------------------------------------------------------------- /angular-mfe2/src/app/components/welcome/welcome.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { WelcomeComponent } from './welcome.component'; 4 | 5 | describe('WelcomeComponent', () => { 6 | let component: WelcomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ WelcomeComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(WelcomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/components/welcome/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-welcome', 5 | templateUrl: './welcome.component.html', 6 | styleUrls: ['./welcome.component.less'] 7 | }) 8 | export class WelcomeComponent { 9 | } 10 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/models/event-bus.service.d.ts: -------------------------------------------------------------------------------- 1 | export type EventBusService = { 2 | readonly name: string; 3 | onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 4 | onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 5 | /** 6 | * Closes the BroadcastChannel object, opening it up to garbage collection. 7 | */ 8 | close(): void; 9 | /** 10 | * Sends the given message to other BroadcastChannel objects set up for this channel. Messages can be structured objects, e.g. nested objects and arrays. 11 | */ 12 | postMessage(message: any): void; 13 | addEventListener(type: string, listener: (this: BroadcastChannel, ev: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void; 14 | removeEventListener(type: K, listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, options?: boolean | EventListenerOptions): void; 15 | removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; 16 | } 17 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/models/note.model.ts: -------------------------------------------------------------------------------- 1 | export type Note = { 2 | id: string; 3 | subject: string; 4 | body: string; 5 | type: string; 6 | } 7 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/notes-counter-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {RouterModule, Routes} from '@angular/router'; 4 | import {NotesCounterComponent} from './notes-counter/notes-counter.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: 'notesCounter', 9 | component: NotesCounterComponent, 10 | pathMatch: 'full' 11 | }, 12 | { 13 | path: '**', 14 | redirectTo: 'notesCounter' 15 | }, 16 | { 17 | path: '', 18 | pathMatch: 'full', 19 | redirectTo: 'notesCounter' 20 | } 21 | ]; 22 | 23 | @NgModule({ 24 | declarations: [], 25 | imports: [ 26 | CommonModule, 27 | RouterModule.forChild(routes) 28 | ] 29 | }) 30 | export class NotesCounterRoutingModule { 31 | } 32 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/notes-counter.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {NotesCounterComponent} from './notes-counter/notes-counter.component'; 4 | import {NotesCounterRoutingModule} from './notes-counter-routing.module'; 5 | import {NotesService} from './services/notes.service'; 6 | import {HttpClientModule} from '@angular/common/http'; 7 | 8 | 9 | @NgModule({ 10 | declarations: [ 11 | NotesCounterComponent 12 | ], 13 | imports: [ 14 | CommonModule, 15 | HttpClientModule, 16 | NotesCounterRoutingModule 17 | ], 18 | providers: [ 19 | { 20 | provide: 'NotesService', 21 | useClass: NotesService 22 | } 23 | ] 24 | }) 25 | export class NotesCounterModule { 26 | } 27 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/notes-counter/notes-counter.component.html: -------------------------------------------------------------------------------- 1 |
2 | {{ notesCount$ | async }} 3 |
4 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/notes-counter/notes-counter.component.less: -------------------------------------------------------------------------------- 1 | .notes-counter { 2 | margin: 12px; 3 | background: white; 4 | padding: 12px; 5 | border-radius: 50%; 6 | width: 40px; 7 | height: 40px; 8 | box-sizing: content-box; 9 | display: flex; 10 | align-items: center; 11 | justify-content: center; 12 | color: black; 13 | box-shadow: 0 0 15px; 14 | } 15 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/notes-counter/notes-counter.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NotesCounterComponent } from './notes-counter.component'; 4 | 5 | describe('BusinessComponent', () => { 6 | let component: NotesCounterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ NotesCounterComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NotesCounterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/notes-counter/notes-counter.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Inject, OnInit, Optional} from '@angular/core'; 2 | import {BehaviorSubject, Observable} from 'rxjs'; 3 | import {EventBusService} from '../models/event-bus.service'; 4 | import {Note} from '../../../../../../angular-mfe1/src/app/modules/business-module/models/note.model'; 5 | 6 | @Component({ 7 | selector: 'notes-counter', 8 | templateUrl: './notes-counter.component.html', 9 | styleUrls: ['./notes-counter.component.less'] 10 | }) 11 | export class NotesCounterComponent implements OnInit { 12 | notesCount$!: Observable; 13 | notesCountSubject$: BehaviorSubject = new BehaviorSubject(0); 14 | 15 | constructor(@Optional() @Inject('GLOBAL_EVENT_BUS') private pluginEventBus: EventBusService) { 16 | } 17 | 18 | ngOnInit(): void { 19 | this.notesCount$ = this.notesCountSubject$; 20 | this.pluginEventBus?.addEventListener('NotesCountUpdate', (event: MessageEvent) => { 21 | this.notesCountSubject$.next(event.data.payload.count); 22 | }); 23 | this.notesCountSubject$.next(this.getAllNotes()?.length); 24 | } 25 | 26 | private getAllNotes(): Array { 27 | let existingNotes: Array; 28 | const existingNotesString: string | null = window.localStorage.getItem('my_notes'); 29 | if (!existingNotesString) { 30 | existingNotes = []; 31 | } else { 32 | existingNotes = JSON.parse(existingNotesString); 33 | } 34 | return existingNotes; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /angular-mfe2/src/app/modules/notes-counter/services/notes.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {BehaviorSubject, Observable, of} from 'rxjs'; 3 | import {HttpClient} from '@angular/common/http'; 4 | 5 | @Injectable() 6 | export class NotesService { 7 | private static errorSubject$: BehaviorSubject = new BehaviorSubject(''); 8 | 9 | constructor(private httpClient: HttpClient) { 10 | } 11 | 12 | public static getError(): Observable { 13 | return NotesService.errorSubject$; 14 | } 15 | 16 | public static setError(value: string): void { 17 | NotesService.errorSubject$.next(value); 18 | } 19 | 20 | public getAllNotes(): Observable { 21 | return of(1); 22 | } 23 | 24 | public loadDnsId(): Observable { 25 | return this.httpClient.get( 26 | 'https://public-gateway-cloudbss-kube-cpm-dev1.k8s-apps.openshift.sdntest.netcracker.com/api/v4/tenant-manager/registration/tenants?dns=cpq', 27 | { 28 | responseType: 'text' 29 | } 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /angular-mfe2/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe2/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-mfe2/src/bootstrap.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-mfe2/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-mfe2/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-mfe2/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe2/src/favicon.ico -------------------------------------------------------------------------------- /angular-mfe2/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularMfe2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /angular-mfe2/src/main.ts: -------------------------------------------------------------------------------- 1 | import('./bootstrap') 2 | .catch(err => console.error(err)); 3 | -------------------------------------------------------------------------------- /angular-mfe2/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * IE11 requires the following for NgClass support on SVG elements 23 | */ 24 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 25 | 26 | /** 27 | * Web Animations `@angular/platform-browser/animations` 28 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 29 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 30 | */ 31 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 32 | 33 | /** 34 | * By default, zone.js will patch all possible macroTask and DomEvents 35 | * user can disable parts of macroTask/DomEvents patch by setting following flags 36 | * because those flags need to be set before `zone.js` being loaded, and webpack 37 | * will put import in the top of bundle, so user need to create a separate file 38 | * in this directory (for example: zone-flags.ts), and put the following flags 39 | * into that file, and then add the following code before importing zone.js. 40 | * import './zone-flags'; 41 | * 42 | * The flags allowed in zone-flags.ts are listed here. 43 | * 44 | * The following flags will work for all browsers. 45 | * 46 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 47 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 48 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 49 | * 50 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 51 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 52 | * 53 | * (window as any).__Zone_enable_cross_context_check = true; 54 | * 55 | */ 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by default for Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | /*************************************************************************************************** 64 | * APPLICATION IMPORTS 65 | */ 66 | -------------------------------------------------------------------------------- /angular-mfe2/src/styles.less: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular-mfe2/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /angular-mfe2/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /angular-mfe2/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "es2015", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ] 23 | }, 24 | "angularCompilerOptions": { 25 | "enableI18nLegacyMessageIdFormat": false, 26 | "strictInjectionParameters": true, 27 | "strictInputAccessModifiers": true, 28 | "strictTemplates": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /angular-mfe2/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-mfe2/webpack.config.js: -------------------------------------------------------------------------------- 1 | const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); 2 | const mf = require("@angular-architects/module-federation/webpack"); 3 | const path = require("path"); 4 | const dependencies = require("./package.json").dependencies; 5 | 6 | const sharedMappings = new mf.SharedMappings(); 7 | sharedMappings.register( 8 | path.join(__dirname, 'tsconfig.json'), 9 | [/* mapped paths to share */]); 10 | 11 | module.exports = { 12 | output: { 13 | uniqueName: "angular_mfe_2", 14 | publicPath: "auto" 15 | }, 16 | optimization: { 17 | runtimeChunk: false 18 | }, 19 | resolve: { 20 | alias: { 21 | ...sharedMappings.getAliases(), 22 | } 23 | }, 24 | plugins: [ 25 | new ModuleFederationPlugin({ 26 | name: "angular_mfe_2", 27 | library: {type: "var", name: "angular_mfe_2"}, 28 | filename: "remoteEntry.js", 29 | exposes: { 30 | NotesCounter: "./src/app/modules/notes-counter/notes-counter/notes-counter.component.ts", 31 | NotesCounterModule: "./src/app/modules/notes-counter/notes-counter.module.ts", 32 | }, 33 | shared: { 34 | '@angular/common/http': { 35 | version: dependencies['@angular/common'], 36 | requiredVersion: dependencies['@angular/common'], 37 | singleton: true, 38 | 39 | }, 40 | '@angular/common': { 41 | version: dependencies['@angular/common'], 42 | requiredVersion: dependencies['@angular/common'], 43 | singleton: true, 44 | 45 | }, 46 | '@angular/core': { 47 | version: dependencies['@angular/core'], 48 | requiredVersion: dependencies['@angular/core'], 49 | singleton: true, 50 | 51 | }, 52 | '@angular/platform-browser': { 53 | version: dependencies['@angular/platform-browser'], 54 | requiredVersion: dependencies['@angular/platform-browser'], 55 | singleton: true, 56 | 57 | }, 58 | '@angular/platform-browser-dynamic': { 59 | version: dependencies['@angular/platform-browser-dynamic'], 60 | requiredVersion: dependencies['@angular/platform-browser-dynamic'], 61 | singleton: true, 62 | 63 | }, 64 | '@angular/router': { 65 | version: dependencies['@angular/router'], 66 | requiredVersion: dependencies['@angular/router'], 67 | singleton: true, 68 | 69 | }, 70 | '@angular/cdk/a11y': { 71 | version: dependencies['@angular/cdk/a11y'], 72 | requiredVersion: dependencies['@angular/cdk/a11y'], 73 | singleton: true, 74 | 75 | }, 76 | '@angular/animations': { 77 | version: dependencies['@angular/animations'], 78 | requiredVersion: dependencies['@angular/animations'], 79 | singleton: true, 80 | 81 | } 82 | } 83 | }), 84 | ], 85 | }; 86 | -------------------------------------------------------------------------------- /angular-mfe2/webpack.prod.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./webpack.config'); 2 | -------------------------------------------------------------------------------- /angular-mfe3/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /angular-mfe3/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /angular-mfe3/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /angular-mfe3/README.md: -------------------------------------------------------------------------------- 1 | # AngularMfe2 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.2.9. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /angular-mfe3/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /angular-mfe3/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { browser, logging } from 'protractor'; 2 | import { AppPage } from './app.po'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('angular-mfe3 app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /angular-mfe3/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-mfe3/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular-mfe3/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/angular-mfe3'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular-mfe3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-mfe3", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:prod": "ng serve --prod", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "run:all": "node node_modules/@angular-architects/module-federation/src/server/mf-dev-server.js" 13 | }, 14 | "private": true, 15 | "resolutions": { 16 | "webpack": "^5.0.0" 17 | }, 18 | "dependencies": { 19 | "@angular-architects/module-federation": "^12.5.2", 20 | "@angular/animations": "12.1.1", 21 | "@angular/common": "12.1.1", 22 | "@angular/compiler": "12.1.1", 23 | "@angular/core": "12.1.1", 24 | "@angular/forms": "12.1.1", 25 | "@angular/platform-browser": "12.1.1", 26 | "@angular/platform-browser-dynamic": "12.1.1", 27 | "@angular/router": "12.1.1", 28 | "rxjs": "~6.6.0", 29 | "tslib": "^2.0.0", 30 | "zone.js": "~0.11.3" 31 | }, 32 | "devDependencies": { 33 | "@angular-devkit/build-angular": "^12.1.1", 34 | "@angular/cli": "12.2.3", 35 | "@angular/compiler-cli": "12.1.1", 36 | "@types/jasmine": "~3.6.0", 37 | "@types/node": "^12.11.1", 38 | "codelyzer": "^6.0.0", 39 | "jasmine-core": "~3.6.0", 40 | "jasmine-spec-reporter": "~5.0.0", 41 | "karma": "~6.1.0", 42 | "karma-chrome-launcher": "~3.1.0", 43 | "karma-coverage": "~2.0.3", 44 | "karma-jasmine": "~4.0.0", 45 | "karma-jasmine-html-reporter": "^1.5.0", 46 | "ngx-build-plus": "^12.0.1", 47 | "protractor": "~7.0.0", 48 | "ts-node": "~8.3.0", 49 | "tslint": "~6.1.0", 50 | "typescript": "4.3.5" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule, Routes} from '@angular/router'; 3 | import {WelcomeComponent} from './components/welcome/welcome.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: 'business', 8 | loadChildren: () => import('./modules/notes-counter/notes-counter.module').then((module) => module.NotesCounterModule), 9 | }, 10 | { 11 | path: '', 12 | pathMatch: 'full', 13 | component: WelcomeComponent 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forRoot(routes)], 19 | exports: [RouterModule] 20 | }) 21 | export class AppRoutingModule { 22 | } 23 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/app.component.less: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe3/src/app/app.component.less -------------------------------------------------------------------------------- /angular-mfe3/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular-mfe3'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('angular-mfe3'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('angular-mfe3 app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.less'] 7 | }) 8 | export class AppComponent { 9 | title = 'angular-mfe3'; 10 | } 11 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import {WelcomeComponent} from './components/welcome/welcome.component'; 7 | import {RouterModule} from '@angular/router'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent, 12 | WelcomeComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | AppRoutingModule, 17 | RouterModule, 18 | RouterModule 19 | ], 20 | providers: [], 21 | bootstrap: [AppComponent] 22 | }) 23 | export class AppModule { } 24 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/components/welcome/welcome.component.html: -------------------------------------------------------------------------------- 1 |

welcome works!

2 | Notes counter link 3 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/components/welcome/welcome.component.less: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe3/src/app/components/welcome/welcome.component.less -------------------------------------------------------------------------------- /angular-mfe3/src/app/components/welcome/welcome.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { WelcomeComponent } from './welcome.component'; 4 | 5 | describe('WelcomeComponent', () => { 6 | let component: WelcomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ WelcomeComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(WelcomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/components/welcome/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-welcome', 5 | templateUrl: './welcome.component.html', 6 | styleUrls: ['./welcome.component.less'] 7 | }) 8 | export class WelcomeComponent { 9 | } 10 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/models/event-bus.service.d.ts: -------------------------------------------------------------------------------- 1 | export type EventBusService = { 2 | readonly name: string; 3 | onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 4 | onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 5 | /** 6 | * Closes the BroadcastChannel object, opening it up to garbage collection. 7 | */ 8 | close(): void; 9 | /** 10 | * Sends the given message to other BroadcastChannel objects set up for this channel. Messages can be structured objects, e.g. nested objects and arrays. 11 | */ 12 | postMessage(message: any): void; 13 | addEventListener(type: string, listener: (this: BroadcastChannel, ev: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void; 14 | removeEventListener(type: K, listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, options?: boolean | EventListenerOptions): void; 15 | removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; 16 | } 17 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/models/note.model.ts: -------------------------------------------------------------------------------- 1 | export type Note = { 2 | id: string; 3 | subject: string; 4 | body: string; 5 | type: string; 6 | } 7 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/notes-counter-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {RouterModule, Routes} from '@angular/router'; 4 | import {NotesCounterComponent} from './notes-counter/notes-counter.component'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: 'notesCounter', 9 | component: NotesCounterComponent, 10 | pathMatch: 'full' 11 | }, 12 | { 13 | path: '**', 14 | redirectTo: 'notesCounter' 15 | }, 16 | { 17 | path: '', 18 | pathMatch: 'full', 19 | redirectTo: 'notesCounter' 20 | } 21 | ]; 22 | 23 | @NgModule({ 24 | declarations: [], 25 | imports: [ 26 | CommonModule, 27 | RouterModule.forChild(routes) 28 | ] 29 | }) 30 | export class NotesCounterRoutingModule { 31 | } 32 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/notes-counter.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {NotesCounterComponent} from './notes-counter/notes-counter.component'; 4 | import {NotesCounterRoutingModule} from './notes-counter-routing.module'; 5 | import {NotesService} from './services/notes.service'; 6 | import {HttpClientModule} from '@angular/common/http'; 7 | 8 | 9 | @NgModule({ 10 | declarations: [ 11 | NotesCounterComponent 12 | ], 13 | imports: [ 14 | CommonModule, 15 | HttpClientModule, 16 | NotesCounterRoutingModule 17 | ], 18 | providers: [ 19 | { 20 | provide: 'NotesService', 21 | useClass: NotesService 22 | } 23 | ] 24 | }) 25 | export class NotesCounterModule { 26 | } 27 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/notes-counter/notes-counter.component.html: -------------------------------------------------------------------------------- 1 |
2 | {{ notesCount$ | async }} 3 |
4 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/notes-counter/notes-counter.component.less: -------------------------------------------------------------------------------- 1 | .notes-counter { 2 | margin: 12px; 3 | background: white; 4 | padding: 12px; 5 | border-radius: 50%; 6 | width: 40px; 7 | height: 40px; 8 | box-sizing: content-box; 9 | display: flex; 10 | align-items: center; 11 | justify-content: center; 12 | color: black; 13 | box-shadow: 0 0 15px; 14 | } 15 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/notes-counter/notes-counter.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NotesCounterComponent } from './notes-counter.component'; 4 | 5 | describe('BusinessComponent', () => { 6 | let component: NotesCounterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ NotesCounterComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NotesCounterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/notes-counter/notes-counter.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Inject, OnInit, Optional} from '@angular/core'; 2 | import {BehaviorSubject, Observable} from 'rxjs'; 3 | import {EventBusService} from '../models/event-bus.service'; 4 | import {Note} from '../../../../../../angular-mfe1/src/app/modules/business-module/models/note.model'; 5 | 6 | @Component({ 7 | selector: 'notes-counter', 8 | templateUrl: './notes-counter.component.html', 9 | styleUrls: ['./notes-counter.component.less'] 10 | }) 11 | export class NotesCounterComponent implements OnInit { 12 | notesCount$!: Observable; 13 | notesCountSubject$: BehaviorSubject = new BehaviorSubject(0); 14 | 15 | constructor(@Optional() @Inject('GLOBAL_EVENT_BUS') private pluginEventBus: EventBusService) { 16 | } 17 | 18 | ngOnInit(): void { 19 | this.notesCount$ = this.notesCountSubject$; 20 | this.pluginEventBus?.addEventListener('NotesCountUpdate', (event: MessageEvent) => { 21 | this.notesCountSubject$.next(event.data.payload.count); 22 | }); 23 | this.notesCountSubject$.next(this.getAllNotes()?.length); 24 | } 25 | 26 | private getAllNotes(): Array { 27 | let existingNotes: Array; 28 | const existingNotesString: string | null = window.localStorage.getItem('my_notes'); 29 | if (!existingNotesString) { 30 | existingNotes = []; 31 | } else { 32 | existingNotes = JSON.parse(existingNotesString); 33 | } 34 | return existingNotes; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /angular-mfe3/src/app/modules/notes-counter/services/notes.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {BehaviorSubject, Observable, of} from 'rxjs'; 3 | import {HttpClient} from '@angular/common/http'; 4 | 5 | @Injectable() 6 | export class NotesService { 7 | private static errorSubject$: BehaviorSubject = new BehaviorSubject(''); 8 | 9 | constructor(private httpClient: HttpClient) { 10 | } 11 | 12 | public static getError(): Observable { 13 | return NotesService.errorSubject$; 14 | } 15 | 16 | public static setError(value: string): void { 17 | NotesService.errorSubject$.next(value); 18 | } 19 | 20 | public getAllNotes(): Observable { 21 | return of(1); 22 | } 23 | 24 | public loadDnsId(): Observable { 25 | return this.httpClient.get( 26 | 'https://public-gateway-cloudbss-kube-cpm-dev1.k8s-apps.openshift.sdntest.netcracker.com/api/v4/tenant-manager/registration/tenants?dns=cpq', 27 | { 28 | responseType: 'text' 29 | } 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /angular-mfe3/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe3/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-mfe3/src/bootstrap.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-mfe3/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-mfe3/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-mfe3/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-mfe3/src/favicon.ico -------------------------------------------------------------------------------- /angular-mfe3/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularMfe2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /angular-mfe3/src/main.ts: -------------------------------------------------------------------------------- 1 | import('./bootstrap') 2 | .catch(err => console.error(err)); 3 | -------------------------------------------------------------------------------- /angular-mfe3/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * IE11 requires the following for NgClass support on SVG elements 23 | */ 24 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 25 | 26 | /** 27 | * Web Animations `@angular/platform-browser/animations` 28 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 29 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 30 | */ 31 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 32 | 33 | /** 34 | * By default, zone.js will patch all possible macroTask and DomEvents 35 | * user can disable parts of macroTask/DomEvents patch by setting following flags 36 | * because those flags need to be set before `zone.js` being loaded, and webpack 37 | * will put import in the top of bundle, so user need to create a separate file 38 | * in this directory (for example: zone-flags.ts), and put the following flags 39 | * into that file, and then add the following code before importing zone.js. 40 | * import './zone-flags'; 41 | * 42 | * The flags allowed in zone-flags.ts are listed here. 43 | * 44 | * The following flags will work for all browsers. 45 | * 46 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 47 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 48 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 49 | * 50 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 51 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 52 | * 53 | * (window as any).__Zone_enable_cross_context_check = true; 54 | * 55 | */ 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by default for Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | /*************************************************************************************************** 64 | * APPLICATION IMPORTS 65 | */ 66 | -------------------------------------------------------------------------------- /angular-mfe3/src/styles.less: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular-mfe3/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /angular-mfe3/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /angular-mfe3/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": true, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "es2015", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ] 23 | }, 24 | "angularCompilerOptions": { 25 | "enableI18nLegacyMessageIdFormat": false, 26 | "strictInjectionParameters": true, 27 | "strictInputAccessModifiers": true, 28 | "strictTemplates": true 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /angular-mfe3/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-mfe3/webpack.config.js: -------------------------------------------------------------------------------- 1 | const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); 2 | const mf = require("@angular-architects/module-federation/webpack"); 3 | const path = require("path"); 4 | const dependencies = require("./package.json").dependencies; 5 | 6 | const sharedMappings = new mf.SharedMappings(); 7 | sharedMappings.register( 8 | path.join(__dirname, 'tsconfig.json'), 9 | [/* mapped paths to share */]); 10 | 11 | module.exports = { 12 | output: { 13 | uniqueName: "angular_mfe_3", 14 | publicPath: "auto" 15 | }, 16 | optimization: { 17 | runtimeChunk: false 18 | }, 19 | resolve: { 20 | alias: { 21 | ...sharedMappings.getAliases(), 22 | } 23 | }, 24 | plugins: [ 25 | new ModuleFederationPlugin({ 26 | name: "angular_mfe_3", 27 | library: {type: "var", name: "angular_mfe_3"}, 28 | filename: "remoteEntry.js", 29 | exposes: { 30 | NotesCounter: "./src/app/modules/notes-counter/notes-counter/notes-counter.component.ts", 31 | NotesCounterModule: "./src/app/modules/notes-counter/notes-counter.module.ts", 32 | }, 33 | shared: { 34 | '@angular/common/http': { 35 | version: dependencies['@angular/common'], 36 | requiredVersion: dependencies['@angular/common'], 37 | singleton: true, 38 | 39 | }, 40 | '@angular/common': { 41 | version: dependencies['@angular/common'], 42 | requiredVersion: dependencies['@angular/common'], 43 | singleton: true, 44 | 45 | }, 46 | '@angular/core': { 47 | version: dependencies['@angular/core'], 48 | requiredVersion: dependencies['@angular/core'], 49 | singleton: true, 50 | 51 | }, 52 | '@angular/platform-browser': { 53 | version: dependencies['@angular/platform-browser'], 54 | requiredVersion: dependencies['@angular/platform-browser'], 55 | singleton: true, 56 | 57 | }, 58 | '@angular/platform-browser-dynamic': { 59 | version: dependencies['@angular/platform-browser-dynamic'], 60 | requiredVersion: dependencies['@angular/platform-browser-dynamic'], 61 | singleton: true, 62 | 63 | }, 64 | '@angular/router': { 65 | version: dependencies['@angular/router'], 66 | requiredVersion: dependencies['@angular/router'], 67 | singleton: true, 68 | 69 | }, 70 | '@angular/cdk/a11y': { 71 | version: dependencies['@angular/cdk/a11y'], 72 | requiredVersion: dependencies['@angular/cdk/a11y'], 73 | singleton: true, 74 | 75 | }, 76 | '@angular/animations': { 77 | version: dependencies['@angular/animations'], 78 | requiredVersion: dependencies['@angular/animations'], 79 | singleton: true, 80 | 81 | } 82 | } 83 | }), 84 | ], 85 | }; 86 | -------------------------------------------------------------------------------- /angular-mfe3/webpack.prod.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./webpack.config'); 2 | -------------------------------------------------------------------------------- /angular-shell/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 18 | -------------------------------------------------------------------------------- /angular-shell/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /angular-shell/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /angular-shell/README.md: -------------------------------------------------------------------------------- 1 | # AngularShell 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.2.9. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /angular-shell/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | SELENIUM_PROMISE_MANAGER: false, 20 | baseUrl: 'http://localhost:4200/', 21 | framework: 'jasmine', 22 | jasmineNodeOpts: { 23 | showColors: true, 24 | defaultTimeoutInterval: 30000, 25 | print: function() {} 26 | }, 27 | onPrepare() { 28 | require('ts-node').register({ 29 | project: require('path').join(__dirname, './tsconfig.json') 30 | }); 31 | jasmine.getEnv().addReporter(new SpecReporter({ 32 | spec: { 33 | displayStacktrace: StacktraceOption.PRETTY 34 | } 35 | })); 36 | } 37 | }; -------------------------------------------------------------------------------- /angular-shell/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { browser, logging } from 'protractor'; 2 | import { AppPage } from './app.po'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', async () => { 12 | await page.navigateTo(); 13 | expect(await page.getTitleText()).toEqual('angular-shell app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /angular-shell/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | async navigateTo(): Promise { 5 | return browser.get(browser.baseUrl); 6 | } 7 | 8 | async getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular-shell/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /angular-shell/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/angular-shell'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular-shell/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-shell", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:prod": "ng serve --prod", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e", 12 | "run:all": "node node_modules/@angular-architects/module-federation/src/server/mf-dev-server.js" 13 | }, 14 | "private": true, 15 | "resolutions": { 16 | "webpack": "^5.0.0" 17 | }, 18 | "dependencies": { 19 | "@angular-architects/module-federation": "12.1.1", 20 | "@angular/animations": "~11.2.10", 21 | "@angular/common": "~11.2.10", 22 | "@angular/compiler": "~11.2.10", 23 | "@angular/core": "~11.2.10", 24 | "@angular/forms": "~11.2.10", 25 | "@angular/platform-browser": "~11.2.10", 26 | "@angular/platform-browser-dynamic": "~11.2.10", 27 | "@angular/router": "~11.2.10", 28 | "react": "^16.13.0", 29 | "react-dom": "^16.8.1", 30 | "vue": "^3.0.11", 31 | "rxjs": "~6.6.0", 32 | "tslib": "^2.0.0", 33 | "zone.js": "~0.11.3" 34 | }, 35 | "devDependencies": { 36 | "@angular-devkit/build-angular": "~0.1102.9", 37 | "@angular/cli": "~11.2.9", 38 | "@angular/compiler-cli": "~11.2.10", 39 | "@types/jasmine": "~3.6.0", 40 | "@types/node": "^12.11.1", 41 | "codelyzer": "^6.0.0", 42 | "jasmine-core": "~3.6.0", 43 | "jasmine-spec-reporter": "~5.0.0", 44 | "karma": "~6.1.0", 45 | "karma-chrome-launcher": "~3.1.0", 46 | "karma-coverage": "~2.0.3", 47 | "karma-jasmine": "~4.0.0", 48 | "karma-jasmine-html-reporter": "^1.5.0", 49 | "ng-packagr": "11.0.3", 50 | "ngx-build-plus": "10.1.1", 51 | "protractor": "~7.0.0", 52 | "ts-node": "~8.3.0", 53 | "tslint": "~6.1.0", 54 | "typescript": "~4.1.5" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /angular-shell/sampleConfiguration.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "angular", 3 | "subType": "module", 4 | "remoteEntry": "http://localhost:4201/remoteEntry.js", 5 | "remoteName": "angular_mfe_1", 6 | "exposedModule": "MfeModule", 7 | "displayName": "First lazy module plugin", 8 | "routePath": "firstModule", 9 | "moduleName": "BusinessModule" 10 | } 11 | -------------------------------------------------------------------------------- /angular-shell/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule} from '@angular/router'; 3 | 4 | 5 | @NgModule({ 6 | imports: [RouterModule.forRoot([])], 7 | exports: [RouterModule] 8 | }) 9 | export class AppRoutingModule { 10 | } 11 | -------------------------------------------------------------------------------- /angular-shell/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async () => { 7 | await TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | }); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'angular-shell'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('angular-shell'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('angular-shell app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /angular-shell/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Injectable, OnInit} from '@angular/core'; 2 | import {FederationPlugin} from './microfrontends/microfrontend.model'; 3 | import {Observable, of} from 'rxjs'; 4 | import {catchError, shareReplay} from 'rxjs/operators'; 5 | import {FederationPluginService} from './microfrontends/federation-plugin.service'; 6 | 7 | @Injectable() 8 | export class TestService { 9 | getAllNotes: () => Observable; 10 | loadDnsId: () => Observable; 11 | } 12 | 13 | @Component({ 14 | selector: 'app-root', 15 | templateUrl: './app.component.html', 16 | styleUrls: ['./app.component.less'], 17 | }) 18 | export class AppComponent implements OnInit { 19 | routes$: Observable>; 20 | notesCounterConfiguration$: Observable; 21 | notesCounterExtendedConfiguration$: Observable; 22 | notesCounterExtended12Configuration$: Observable; 23 | 24 | constructor(private federationPluginService: FederationPluginService) { 25 | } 26 | 27 | private get notesService(): Promise { 28 | return this.federationPluginService.getRemoteService('notesService'); 29 | } 30 | 31 | ngOnInit(): void { 32 | this.routes$ = this.federationPluginService.loadRoutesConfig().pipe(shareReplay(1)); 33 | this.notesCounterConfiguration$ = this.federationPluginService.getRemoteComponentConfiguration('notesCounter'); 34 | this.notesCounterExtendedConfiguration$ = this.federationPluginService.getRemoteComponentConfiguration('notesCounterAngular12'); 35 | this.notesCounterExtended12Configuration$ = this.federationPluginService.getRemoteComponentConfiguration('notesCounterAngular12WithProvidersExtended'); 36 | 37 | this.notesService.then((service) => { 38 | service.getAllNotes().subscribe((count) => { 39 | console.log('COUNT: ' + count); 40 | }); 41 | service.loadDnsId() 42 | .pipe( 43 | catchError((error) => { 44 | return of(null); 45 | }) 46 | ) 47 | .subscribe((dnsId: string) => { 48 | console.log('ID: ' + dnsId); 49 | }); 50 | }); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /angular-shell/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {BrowserModule} from '@angular/platform-browser'; 3 | 4 | import {AppRoutingModule} from './app-routing.module'; 5 | import {AppComponent} from './app.component'; 6 | import {AngularWrapperComponent} from './components/angular-wrapper/angular-wrapper.component'; 7 | import {FederationPluginService} from './microfrontends/federation-plugin.service'; 8 | import {WelcomeComponent} from './components/welcome/welcome.component'; 9 | import {EventBusService} from './microfrontends/event-bus.service'; 10 | import {GlobalNavigationService} from './microfrontends/global-navigation.service'; 11 | import {VueWrapperComponent} from './components/vue-wrapper/vue-wrapper.component'; 12 | import {SelfRunWrapperComponent} from './components/self-run-wrapper/self-run-wrapper.component'; 13 | import {ReactWrapperModule} from './modules/react-wrapper/react-wrapper.module'; 14 | 15 | @NgModule({ 16 | declarations: [ 17 | AppComponent, 18 | AngularWrapperComponent, 19 | SelfRunWrapperComponent, 20 | VueWrapperComponent, 21 | WelcomeComponent 22 | ], 23 | imports: [ 24 | BrowserModule, 25 | AppRoutingModule, 26 | ReactWrapperModule 27 | ], 28 | providers: [ 29 | FederationPluginService, 30 | { 31 | provide: 'GLOBAL_EVENT_BUS', 32 | useClass: EventBusService 33 | }, 34 | { 35 | provide: 'GLOBAL_NAVIGATION_SERVICE', 36 | useClass: GlobalNavigationService 37 | }, 38 | { 39 | provide: 'GLOBAL_SERVICES', 40 | useFactory: () => { 41 | } 42 | } 43 | 44 | ], 45 | bootstrap: [AppComponent] 46 | }) 47 | export class AppModule { 48 | } 49 | -------------------------------------------------------------------------------- /angular-shell/src/app/app.service.ts: -------------------------------------------------------------------------------- 1 | import {BehaviorSubject, Observable} from 'rxjs'; 2 | import {FederationPlugin} from './microfrontends/microfrontend.model'; 3 | import {NavigationAlias} from './microfrontends/navigation.const'; 4 | 5 | export class AppService { 6 | private static routesSubject: BehaviorSubject> = new BehaviorSubject([]); 7 | private static routes$: Observable> = AppService.routesSubject; 8 | 9 | private static routeAliasesSubject: BehaviorSubject> = new BehaviorSubject(null); 10 | private static routeAliases$: Observable> = AppService.routeAliasesSubject; 11 | 12 | public static setRouteAliases(routeAliases: Record): void { 13 | AppService.routeAliasesSubject.next(routeAliases); 14 | } 15 | 16 | public static getRouteAliases(): Observable> { 17 | return AppService.routeAliases$; 18 | } 19 | 20 | public static setRoutes(routes: ReadonlyArray): void { 21 | AppService.routesSubject.next(routes); 22 | } 23 | 24 | public static getRoutes(): Observable> { 25 | return AppService.routes$; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /angular-shell/src/app/components/self-run-wrapper/self-run-wrapper.component.ts: -------------------------------------------------------------------------------- 1 | import {AfterContentInit, Component, ElementRef, Input, OnDestroy} from '@angular/core'; 2 | import {ActivatedRoute, Data} from '@angular/router'; 3 | import {take} from 'rxjs/operators'; 4 | import {FederationPlugin} from '../../microfrontends/microfrontend.model'; 5 | import {loadRemoteModule} from '../../utils/federation-utils'; 6 | import {EventBusService} from '../../microfrontends/event-bus.service'; 7 | import {GlobalNavigationService} from '../../microfrontends/global-navigation.service'; 8 | 9 | @Component({ 10 | selector: 'self-run-wrapper', 11 | template: '', 12 | styles: [':host {height: 100%; overflow: auto;}'] 13 | }) 14 | export class SelfRunWrapperComponent implements AfterContentInit, OnDestroy { 15 | 16 | @Input() props: Record; 17 | 18 | constructor(private hostRef: ElementRef, 19 | private route: ActivatedRoute, 20 | private eventBusService: EventBusService, 21 | private globalNavigationService: GlobalNavigationService 22 | ) { 23 | } 24 | 25 | ngOnDestroy(): void { 26 | } 27 | 28 | async ngAfterContentInit(): Promise { 29 | this.route.data 30 | .pipe(take(1)) 31 | .subscribe(async (data: Data) => { 32 | const configuration: FederationPlugin = data.configuration; 33 | const component = await loadRemoteModule({ 34 | remoteEntry: configuration.remoteEntry, 35 | remoteName: configuration.remoteName, 36 | exposedModule: configuration.exposedModule 37 | }); 38 | 39 | const selfRunApp = component[configuration.moduleClassName || 'default']; 40 | selfRunApp(this.hostRef.nativeElement, this.props, configuration.routePath); 41 | }); 42 | } 43 | } 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /angular-shell/src/app/components/vue-wrapper/vue-wrapper.component.ts: -------------------------------------------------------------------------------- 1 | import {AfterContentInit, Component, ElementRef, Input, OnDestroy} from '@angular/core'; 2 | import {ActivatedRoute, Data} from '@angular/router'; 3 | import {take} from 'rxjs/operators'; 4 | import {FederationPlugin} from '../../microfrontends/microfrontend.model'; 5 | import {loadRemoteModule} from '../../utils/federation-utils'; 6 | import {EventBusService} from '../../microfrontends/event-bus.service'; 7 | import {GlobalNavigationService} from '../../microfrontends/global-navigation.service'; 8 | import {createApp} from 'vue'; 9 | 10 | @Component({ 11 | selector: 'vue-wrapper', 12 | template: '', 13 | styles: [':host {height: 100%; overflow: auto;}'] 14 | }) 15 | export class VueWrapperComponent implements AfterContentInit, OnDestroy { 16 | 17 | vueComponentRef; 18 | 19 | @Input() props: Record; 20 | 21 | constructor(private hostRef: ElementRef, 22 | private route: ActivatedRoute, 23 | private eventBusService: EventBusService, 24 | private globalNavigationService: GlobalNavigationService 25 | ) { 26 | } 27 | 28 | async ngAfterContentInit(): Promise { 29 | this.route.data 30 | .pipe(take(1)) 31 | .subscribe(async (data: Data) => { 32 | const configuration: FederationPlugin = data.configuration; 33 | const component = await loadRemoteModule({ 34 | remoteEntry: configuration.remoteEntry, 35 | remoteName: configuration.remoteName, 36 | exposedModule: configuration.exposedModule 37 | }); 38 | 39 | const vueComponent = component[configuration.moduleClassName || 'default']; 40 | this.vueComponentRef = createApp(vueComponent, { 41 | data: () => { 42 | return (this.props || {}); 43 | } 44 | }); 45 | this.vueComponentRef.mount(this.hostRef.nativeElement); 46 | }); 47 | } 48 | 49 | ngOnDestroy(): void { 50 | } 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /angular-shell/src/app/components/welcome/welcome.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
7 | {{ route.displayName }} 8 |
9 |
10 |
11 |
12 | This component part is just to demonstrate passing props to react remote plugin 13 |
14 | 19 | 23 |
24 |
25 | -------------------------------------------------------------------------------- /angular-shell/src/app/components/welcome/welcome.component.less: -------------------------------------------------------------------------------- 1 | .host-welcome { 2 | &__application-selector { 3 | &-item { 4 | margin: 24px; 5 | padding: 24px; 6 | background: white; 7 | box-shadow: 0 0 10px #ccc; 8 | cursor: pointer; 9 | border-radius: 10px; 10 | 11 | &:hover { 12 | background: rgb(250, 250, 250); 13 | } 14 | } 15 | } 16 | 17 | &__react { 18 | padding: 24px; 19 | 20 | &-wrapper { 21 | display: flex; 22 | padding: 8px; 23 | align-items: center; 24 | justify-content: center; 25 | border: solid 1px; 26 | border-radius: 6px; 27 | background: white; 28 | } 29 | 30 | &-button { 31 | margin: 8px 0; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /angular-shell/src/app/components/welcome/welcome.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { WelcomeComponent } from './welcome.component'; 4 | 5 | describe('WelcomeComponent', () => { 6 | let component: WelcomeComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ WelcomeComponent ] 12 | }) 13 | .compileComponents(); 14 | }); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(WelcomeComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular-shell/src/app/components/welcome/welcome.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit} from '@angular/core'; 2 | import {FederationPluginService} from '../../microfrontends/federation-plugin.service'; 3 | import {Observable} from 'rxjs'; 4 | import {FederationPlugin} from '../../microfrontends/microfrontend.model'; 5 | import {AppService} from '../../app.service'; 6 | 7 | @Component({ 8 | selector: 'app-welcome', 9 | templateUrl: './welcome.component.html', 10 | styleUrls: ['./welcome.component.less'] 11 | }) 12 | export class WelcomeComponent implements OnInit { 13 | routes$: Observable>; 14 | reactPluginConfiguration$: Observable; 15 | reactPluginProps: Record = { 16 | basename: '/' 17 | }; 18 | 19 | constructor(private federationPluginService: FederationPluginService) { 20 | } 21 | 22 | ngOnInit(): void { 23 | this.routes$ = AppService.getRoutes(); 24 | this.reactPluginConfiguration$ = this.federationPluginService.getRemoteComponentConfiguration('reactExamplePlugin'); 25 | } 26 | 27 | passReactProps(): void { 28 | this.reactPluginProps = { 29 | ...this.reactPluginProps, 30 | count: Math.random() 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /angular-shell/src/app/microfrontends/event-bus.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | 3 | @Injectable({ 4 | providedIn: 'root' 5 | }) 6 | export class EventBusService { 7 | private consumer: BroadcastChannel; 8 | private producer: BroadcastChannel; 9 | 10 | constructor() { 11 | this.consumer = new BroadcastChannel('pluginGlobalEventBus'); 12 | this.producer = new BroadcastChannel('pluginGlobalEventBus'); 13 | 14 | this.consumer.addEventListener('message', (event) => { 15 | console.log('THIS IS APPLICATION BUS'); 16 | console.log(event); 17 | }); 18 | } 19 | 20 | postMessage(message: any): void { 21 | this.producer.postMessage(message); 22 | } 23 | 24 | addEventListener(eventName, listener): void { 25 | this.consumer.addEventListener('message', (event) => { 26 | if (event.data.name === eventName) { 27 | listener(event); 28 | } 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /angular-shell/src/app/microfrontends/global-navigation.service.ts: -------------------------------------------------------------------------------- 1 | import {Router} from '@angular/router'; 2 | import {AppService} from '../app.service'; 3 | import {take} from 'rxjs/operators'; 4 | import {NavigationAlias} from './navigation.const'; 5 | import {Injectable} from '@angular/core'; 6 | 7 | @Injectable({ 8 | providedIn: 'root' 9 | }) 10 | export class GlobalNavigationService { 11 | 12 | constructor(private router: Router) { 13 | } 14 | 15 | public navigate(routeAlias: NavigationAlias): void { 16 | AppService.getRouteAliases().pipe(take(1)).subscribe((routeAliases: Record) => { 17 | this.router.navigateByUrl(routeAliases[routeAlias]); 18 | }); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /angular-shell/src/app/microfrontends/microfrontend.model.ts: -------------------------------------------------------------------------------- 1 | import { LoadRemoteModuleOptions } from '../utils/federation-utils'; 2 | 3 | export type FederationPlugin = LoadRemoteModuleOptions & { 4 | displayName?: string; 5 | routePath?: string; 6 | moduleName?: string; 7 | moduleClassName?: string; 8 | componentClassName?: string; 9 | serviceClassName?: string; 10 | exposedComponent?: string; 11 | navigationAlias?: string; 12 | type?: 'angular' | 'react' | 'vue'; 13 | subType?: 'routeModule' | 'componentModule' | 'component'; 14 | }; 15 | -------------------------------------------------------------------------------- /angular-shell/src/app/microfrontends/navigation.const.ts: -------------------------------------------------------------------------------- 1 | // TODO: move to lib 2 | export enum NavigationAlias { 3 | NOTES_ADMIN_PANEL = 'NOTES_ADMIN_PANEL', 4 | NOTES_LIST = 'NOTES_LIST' 5 | } 6 | -------------------------------------------------------------------------------- /angular-shell/src/app/modules/react-wrapper/react-wrapper.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule, OnInit} from '@angular/core'; 2 | import {CommonModule} from '@angular/common'; 3 | import {ReactWrapperRoutesRoutingModule} from "./react-wrapper.routes"; 4 | import {ReactWrapperComponent} from './components/react-wrapper/react-wrapper.component'; 5 | 6 | 7 | @NgModule({ 8 | declarations: [ 9 | ReactWrapperComponent 10 | ], 11 | exports: [ 12 | ReactWrapperComponent 13 | ], 14 | imports: [ 15 | CommonModule, 16 | ReactWrapperRoutesRoutingModule 17 | ] 18 | }) 19 | export class ReactWrapperModule { 20 | } 21 | -------------------------------------------------------------------------------- /angular-shell/src/app/modules/react-wrapper/react-wrapper.routes.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule, Routes} from '@angular/router'; 3 | import {ReactWrapperComponent} from './components/react-wrapper/react-wrapper.component'; 4 | 5 | export const REACT_WRAPPER_ROUTES: Routes = [ 6 | { 7 | path: '', 8 | component: ReactWrapperComponent 9 | } 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(REACT_WRAPPER_ROUTES)], 14 | exports: [RouterModule] 15 | }) 16 | export class ReactWrapperRoutesRoutingModule { 17 | } 18 | -------------------------------------------------------------------------------- /angular-shell/src/app/utils/federation-utils.ts: -------------------------------------------------------------------------------- 1 | type Scope = unknown; 2 | type Factory = () => any; 3 | 4 | type Container = { 5 | init(shareScope: Scope, initScope?: Scope): void; 6 | get(module: string, getScope?: Scope): Factory; 7 | }; 8 | 9 | declare const __webpack_init_sharing__: (shareScope: string) => Promise; 10 | declare const __webpack_share_scopes__: { default: Scope, plugin: Scope }; 11 | 12 | const moduleMap = {}; 13 | 14 | export function loadRemoteEntry(remoteEntry: string): Promise { 15 | return new Promise((resolve, reject) => { 16 | if (moduleMap[remoteEntry]) { 17 | resolve(moduleMap[remoteEntry]); 18 | return; 19 | } 20 | 21 | const script = document.createElement('script'); 22 | script.src = remoteEntry; 23 | 24 | script.onerror = reject; 25 | 26 | script.onload = () => { 27 | moduleMap[remoteEntry] = true; 28 | resolve(moduleMap[remoteEntry]); // window is the global namespace 29 | }; 30 | 31 | document.body.append(script); 32 | }); 33 | } 34 | 35 | async function lookupExposedRemote( 36 | remoteName: string, 37 | exposedModule: string 38 | ): Promise { 39 | // Initializes the share scope. This fills it with known provided modules from this build and all remotes 40 | await __webpack_init_sharing__('default'); 41 | const container = window[remoteName] as Container; 42 | 43 | await container.init(__webpack_share_scopes__.default); 44 | const factory = await container.get(exposedModule); 45 | const Module = factory(); 46 | return Module as T; 47 | } 48 | 49 | export type LoadRemoteModuleOptions = { 50 | remoteEntry: string; 51 | remoteName?: string; 52 | exposedModule?: string; 53 | }; 54 | 55 | export async function loadRemoteModule( 56 | options: LoadRemoteModuleOptions 57 | ): Promise { 58 | await loadRemoteEntry(options.remoteEntry); 59 | return await lookupExposedRemote( 60 | options.remoteName, 61 | options.exposedModule 62 | ); 63 | } 64 | 65 | export function InjectMfService(module, service): (target: any) => void { 66 | return function decorator(target): void { 67 | target.noteService = {get: () => 1}; 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /angular-shell/src/app/utils/route-utils.ts: -------------------------------------------------------------------------------- 1 | import {loadRemoteModule} from './federation-utils'; 2 | import {Routes} from '@angular/router'; 3 | import {FederationPlugin} from '../microfrontends/microfrontend.model'; 4 | import {WelcomeComponent} from '../components/welcome/welcome.component'; 5 | import {VueWrapperComponent} from '../components/vue-wrapper/vue-wrapper.component'; 6 | import {SelfRunWrapperComponent} from '../components/self-run-wrapper/self-run-wrapper.component'; 7 | 8 | const APPLICATION_ROUTES: Routes = [ 9 | { 10 | path: '', 11 | pathMatch: 'full', 12 | component: WelcomeComponent 13 | } 14 | ]; 15 | 16 | export function buildRoutes(options: ReadonlyArray): Routes { 17 | const lazyRoutes: Routes = options?.map((mfe: FederationPlugin) => { 18 | switch (mfe.type) { 19 | case 'angular': { 20 | switch (mfe.subType) { 21 | case 'routeModule': { 22 | return { 23 | path: mfe.routePath, 24 | loadChildren: () => loadRemoteModule(mfe).then((m) => m[mfe.moduleClassName]), 25 | }; 26 | } 27 | default: { 28 | return { 29 | path: mfe.routePath, 30 | loadChildren: () => loadRemoteModule(mfe).then((m) => m[mfe.moduleClassName]), 31 | }; 32 | } 33 | } 34 | } 35 | case 'react': { 36 | return { 37 | path: mfe.routePath, 38 | children: [ 39 | { 40 | path: '**', 41 | loadChildren: () => import('../modules/react-wrapper/react-wrapper.module').then((m) => { 42 | return m.ReactWrapperModule; 43 | }), 44 | data: {configuration: mfe}, 45 | } 46 | ] 47 | }; 48 | } 49 | case 'vue': { 50 | return { 51 | path: mfe.routePath, 52 | children: [ 53 | { 54 | path: '**', 55 | component: VueWrapperComponent, 56 | data: {configuration: mfe} 57 | } 58 | ] 59 | }; 60 | } 61 | default: { 62 | return { 63 | path: mfe.routePath, // TODO: add UnknownPluginType component to catch incorrect configuration 64 | children: [ 65 | { 66 | path: '**', 67 | component: SelfRunWrapperComponent, 68 | data: {configuration: mfe} 69 | } 70 | ] 71 | }; 72 | } 73 | } 74 | }); 75 | 76 | return [...(lazyRoutes || []), ...APPLICATION_ROUTES]; 77 | } 78 | -------------------------------------------------------------------------------- /angular-shell/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-shell/src/assets/.gitkeep -------------------------------------------------------------------------------- /angular-shell/src/bootstrap.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /angular-shell/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular-shell/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /angular-shell/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/angular-shell/src/favicon.ico -------------------------------------------------------------------------------- /angular-shell/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularShell 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /angular-shell/src/main.ts: -------------------------------------------------------------------------------- 1 | import('./bootstrap') 2 | .catch(err => console.error(err)); 3 | -------------------------------------------------------------------------------- /angular-shell/src/styles.less: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular-shell/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /angular-shell/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /angular-shell/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": false, 9 | "noImplicitReturns": true, 10 | "noFallthroughCasesInSwitch": false, 11 | "sourceMap": true, 12 | "declaration": false, 13 | "downlevelIteration": true, 14 | "experimentalDecorators": true, 15 | "moduleResolution": "node", 16 | "importHelpers": true, 17 | "target": "es2015", 18 | "module": "es2020", 19 | "lib": [ 20 | "es2018", 21 | "dom" 22 | ], 23 | "jsx": "react" 24 | }, 25 | "angularCompilerOptions": { 26 | "enableI18nLegacyMessageIdFormat": false, 27 | "strictInjectionParameters": true, 28 | "strictInputAccessModifiers": true, 29 | "strictTemplates": true 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /angular-shell/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /angular-shell/webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require("webpack"); 2 | const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin"); 3 | const mf = require("@angular-architects/module-federation/webpack"); 4 | const path = require("path"); 5 | const dependencies = require("./package.json").dependencies; 6 | 7 | const sharedMappings = new mf.SharedMappings(); 8 | sharedMappings.register( 9 | path.join(__dirname, 'tsconfig.json'), 10 | [/* mapped paths to share */]); 11 | 12 | module.exports = { 13 | output: { 14 | uniqueName: "angularShell", 15 | publicPath: "auto" 16 | }, 17 | optimization: { 18 | runtimeChunk: false 19 | }, 20 | resolve: { 21 | alias: { 22 | ...sharedMappings.getAliases(), 23 | } 24 | }, 25 | plugins: [ 26 | new webpack.ProvidePlugin({ 27 | "React": "react", 28 | }), 29 | new ModuleFederationPlugin({ 30 | shared: { 31 | '@angular/common/http': { 32 | requiredVersion: dependencies['@angular/common'], 33 | singleton: false, 34 | eager: true 35 | }, 36 | '@angular/common': { 37 | version: dependencies['@angular/common'], 38 | singleton: false, 39 | eager: true 40 | }, 41 | '@angular/core': { 42 | version: dependencies['@angular/core'], 43 | requiredVersion: dependencies['@angular/core'], 44 | singleton: false, 45 | eager: true 46 | }, 47 | '@angular/platform-browser': { 48 | version: dependencies['@angular/platform-browser'], 49 | requiredVersion: dependencies['@angular/platform-browser'], 50 | singleton: false, 51 | eager: true 52 | }, 53 | '@angular/platform-browser-dynamic': { 54 | version: dependencies['@angular/platform-browser-dynamic'], 55 | requiredVersion: dependencies['@angular/platform-browser-dynamic'], 56 | singleton: false, 57 | eager: true 58 | }, 59 | '@angular/router': { 60 | version: dependencies['@angular/router'], 61 | requiredVersion: dependencies['@angular/router'], 62 | singleton: false, 63 | eager: true 64 | }, 65 | '@angular/cdk/a11y': { 66 | version: dependencies['@angular/cdk/a11y'], 67 | requiredVersion: dependencies['@angular/cdk/a11y'], 68 | singleton: false, 69 | eager: true 70 | }, 71 | '@angular/animations': { 72 | version: dependencies['@angular/animations'], 73 | requiredVersion: dependencies['@angular/animations'], 74 | singleton: false, 75 | eager: true 76 | }, 77 | } 78 | 79 | }) 80 | ], 81 | }; 82 | -------------------------------------------------------------------------------- /angular-shell/webpack.prod.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./webpack.config'); 2 | -------------------------------------------------------------------------------- /multi-framework-module-federation.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multi-module-federation-aggregator", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "deps:all": "npm-run-all --parallel deps:shell deps:mfe1 deps:mfe2 deps:mfe3 deps:mfe1 deps:react:mfe1 deps:react:mfe2 deps:vue:mfe1", 7 | "start:all": "concurrently --kill-others \"yarn start:shell\" \"yarn start:mfe1\" \"yarn start:mfe2\" \"yarn start:mfe3\" \"yarn start:react:mfe1\" \"yarn start:react:mfe2\" \"yarn start:vue:mfe1\"", 8 | "start:angular:all:dev": "concurrently --kill-others \"yarn start:shell\" \"yarn start:mfe1\" \"yarn start:mfe2\" \"yarn start:mfe3\"", 9 | "start:react:all:dev": "concurrently --kill-others \"yarn start:react:mfe1\" \"yarn start:react:mfe2\"", 10 | "start:vue:all:dev": "concurrently --kill-others \"yarn start:vue:mfe1\"", 11 | "deps:shell": "cd angular-shell && yarn", 12 | "deps:mfe1": "cd angular-mfe1 && yarn", 13 | "deps:mfe2": "cd angular-mfe2 && yarn", 14 | "deps:mfe3": "cd angular-mfe3 && yarn", 15 | "deps:react:mfe1": "cd react-mfe1 && yarn", 16 | "deps:react:mfe2": "cd react-mfe2 && yarn", 17 | "deps:vue:mfe1": "cd vue-mfe1 && yarn", 18 | "start:shell": "cd angular-shell && yarn start", 19 | "start:mfe1": "cd angular-mfe1 && yarn start", 20 | "start:mfe2": "cd angular-mfe2 && yarn start", 21 | "start:mfe3": "cd angular-mfe3 && yarn start", 22 | "start:react:mfe1": "cd react-mfe1 && yarn start", 23 | "start:react:mfe2": "cd react-mfe2 && yarn start", 24 | "start:vue:mfe1": "cd vue-mfe1 && yarn start" 25 | }, 26 | "license": "MIT", 27 | "devDependencies": { 28 | "concurrently": "^6.2.2", 29 | "npm-run-all": "^4.1.5" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /react-mfe1/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | insert_final_newline = false 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /react-mfe1/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | .DS_STORE 4 | node_modules 5 | .module-cache 6 | *.log* 7 | dist 8 | backup 9 | package-lock.json 10 | build/*.* -------------------------------------------------------------------------------- /react-mfe1/.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine on 2 | # Don't rewrite files or directories 3 | RewriteCond %{REQUEST_FILENAME} -f [OR] 4 | RewriteCond %{REQUEST_FILENAME} -d 5 | RewriteRule ^ - [L] 6 | # Rewrite everything else to index.html to allow html5 state links 7 | RewriteRule ^ index.html [L] 8 | -------------------------------------------------------------------------------- /react-mfe1/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "semi": true, 4 | "useTabs": false, 5 | "tabWidth": 2, 6 | "bracketSpacing": true, 7 | "singleQuote": true, 8 | "jsxBracketSameLine": false, 9 | "printWidth": 100 10 | } 11 | -------------------------------------------------------------------------------- /react-mfe1/README.md: -------------------------------------------------------------------------------- 1 | # Frontend Boilerplate with React, Redux & TypeScript 2 | 3 | A bare minimum react-redux-webpack-typescript boilerplate with TodoMVC example. 4 | 5 | [Live demo](https://rokoroku.github.io/react-redux-typescript-boilerplate) 6 | 7 | Note that this project does not include **Server-Side Rendering**, **Static code analysis**, **Testing Frameworks** and other stuffs that makes the package unnecessarily complicated. (e.g. yarn, tslint, jest, ...) 8 | If needed, please fork this repository and add your own that meets your requirements. 9 | 10 | Ideal for creating React apps from the scratch. 11 | 12 | See also: [react-mobx-typescript-boilerplate](https://github.com/rokoroku/react-mobx-typescript-boilerplate) 13 | 14 | ## Contains 15 | 16 | - [x] [Typescript](https://www.typescriptlang.org/) 3 17 | - [x] [React](https://facebook.github.io/react/) 16.8 18 | - [x] [Redux](https://github.com/reactjs/redux) 4 19 | - [x] [React Router](https://github.com/ReactTraining/react-router) 4.3 20 | - [x] [Redux DevTools Extension](https://github.com/zalmoxisus/redux-devtools-extension) 21 | - [x] [TodoMVC example](http://todomvc.com) 22 | 23 | ### Build tools 24 | 25 | - [x] [Webpack](https://webpack.github.io) 4 26 | - [x] [Tree Shaking](https://medium.com/@Rich_Harris/tree-shaking-versus-dead-code-elimination-d3765df85c80) 27 | - [x] [Webpack Dev Server](https://github.com/webpack/webpack-dev-server) 28 | - [x] [Typescript Loader](https://github.com/TypeStrong/ts-loader) 29 | - [x] [PostCSS Loader](https://github.com/postcss/postcss-loader) 30 | - [x] [PostCSS Preset Env](https://preset-env.cssdb.org/) 31 | - [x] [CSS modules](https://github.com/css-modules/css-modules) 32 | - [x] [React Hot Loader](https://github.com/gaearon/react-hot-loader) 33 | - [x] [Mini CSS Extract Plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 34 | - [x] [HTML Webpack Plugin](https://github.com/ampedandwired/html-webpack-plugin) 35 | 36 | ## Installation 37 | 38 | ``` 39 | $ npm ci 40 | ``` 41 | 42 | ## Running 43 | 44 | ``` 45 | $ npm start 46 | ``` 47 | 48 | ## Build 49 | 50 | ``` 51 | $ npm run build 52 | ``` 53 | 54 | ## Deploy (to the [GitHub Pages](https://pages.github.com/)) 55 | 56 | ``` 57 | $ npm run deploy 58 | ``` 59 | 60 | ## Format code (using [Prettier](https://github.com/prettier/prettier)) 61 | 62 | ``` 63 | $ npm run prettier 64 | ``` 65 | 66 | # License 67 | 68 | MIT 69 | -------------------------------------------------------------------------------- /react-mfe1/generate-react-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "usesTypeScript": true, 3 | "usesCssModule": true, 4 | "cssPreprocessor": "less", 5 | "testLibrary": "None", 6 | "component": { 7 | "default": { 8 | "path": "app/components", 9 | "withStyle": true, 10 | "withTest": true, 11 | "withStory": true, 12 | "withLazy": true 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /react-mfe1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fastener-shop-spa", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "predeploy": "npm run build", 7 | "deploy": "gh-pages -d build", 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "start": "webpack-cli serve", 10 | "start:prod": "webpack-cli -p serve", 11 | "build": "webpack --mode production", 12 | "prettier": "prettier --write \"src/**/*.{ts,tsx,css}\"", 13 | "server": "tsc-watch ./server/server.ts --outDir ./dist --onSuccess \"node ./dist/server.js\" --onFailure \"echo Beep! Compilation Failed\" --compiler typescript/bin/tsc", 14 | "startWithMock": "concurrently \"npm:server\" \"npm:start\"" 15 | }, 16 | "license": "MIT", 17 | "devDependencies": { 18 | "@babel/core": "^7.2.2", 19 | "@types/classnames": "^2.2.7", 20 | "@types/history": "^4.7.2", 21 | "@types/node": "^10.12.18", 22 | "@types/react": "^16.8.2", 23 | "@types/react-dom": "^16.8.0", 24 | "@types/react-redux": "^7.0.0", 25 | "@types/react-router": "^4.4.3", 26 | "@types/react-router-dom": "^4.3.3", 27 | "@types/react-transition-group": "^2.9.1", 28 | "@types/redux-actions": "2.3.1", 29 | "@types/webpack": "^4.4.23", 30 | "@types/webpack-env": "1.13.6", 31 | "babel-loader": "^8.0.5", 32 | "body-parser": "^1.19.0", 33 | "concurrently": "^4.1.0", 34 | "css-loader": "^2.1.0", 35 | "express": "^4.16.4", 36 | "file-loader": "^3.0.1", 37 | "gh-pages": "^2.0.1", 38 | "html-loader": "^1.0.0-alpha.0", 39 | "html-webpack-plugin": "^4.0.0-alpha", 40 | "less": "2.7.2", 41 | "less-loader": "4.0.4", 42 | "mini-css-extract-plugin": "^0.5.0", 43 | "prettier": "^1.15.3", 44 | "react-hot-loader": "^4.6.3", 45 | "redux-devtools-extension": "^2.13.7", 46 | "style-loader": "^0.23.1", 47 | "ts-loader": "^5.3.3", 48 | "tsc-watch": "^2.1.2", 49 | "typescript": "^3.7.5", 50 | "url-loader": "^1.1.2", 51 | "webpack": "5.36.2", 52 | "webpack-cleanup-plugin": "^0.5.1", 53 | "webpack-cli": "4.7.0", 54 | "webpack-dev-server": "3.11.2" 55 | }, 56 | "dependencies": { 57 | "@babel/preset-env": "^7.14.4", 58 | "@babel/preset-react": "^7.13.13", 59 | "@types/lodash.clonedeep": "^4.5.6", 60 | "axios": "^0.18.0", 61 | "classnames": "^2.2.6", 62 | "gulp": "^4.0.2", 63 | "i18next": "^19.4.4", 64 | "lodash.clonedeep": "^4.5.0", 65 | "pure-react-carousel": "^1.27.0", 66 | "react": "^16.13.0", 67 | "react-dom": "^16.8.1", 68 | "react-quill": "^1.3.5", 69 | "react-redux": "^6.0.0", 70 | "react-router": "^4.3.1", 71 | "react-router-dom": "^5.0.0", 72 | "react-shadow-dom-retarget-events": "^1.0.11", 73 | "react-transition-group": "^4.0.1", 74 | "redux": "^4.0.1", 75 | "redux-actions": "^2.6.4", 76 | "redux-thunk": "^2.3.0", 77 | "semantic-ui-css": "^2.4.1", 78 | "semantic-ui-react": "^2.0.3" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /react-mfe1/semantic.json: -------------------------------------------------------------------------------- 1 | { 2 | "base": "semantic/", 3 | "paths": { 4 | "source": { 5 | "config": "src/theme.config", 6 | "definitions": "src/definitions/", 7 | "site": "src/site/", 8 | "themes": "src/themes/" 9 | }, 10 | "output": { 11 | "packaged": "build/", 12 | "uncompressed": "build/components/", 13 | "compressed": "build/components/", 14 | "themes": "build/themes/" 15 | }, 16 | "clean": "build/" 17 | }, 18 | "permission": false, 19 | "autoInstall": false, 20 | "rtl": false, 21 | "version": "2.4.2" 22 | } 23 | -------------------------------------------------------------------------------- /react-mfe1/src/app/components/notes-list.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import {Button, Card} from 'semantic-ui-react'; 3 | import {Note} from 'app/models/note.model'; 4 | import {EventBusService} from 'app/models/event-bus.model'; 5 | import {ApplicationService} from '../../application.service'; 6 | import {GlobalNavigationService} from 'app/models/global-navigation.model'; 7 | import {NavigationAlias} from 'app/models/navigation.const'; 8 | 9 | export interface NotesListProps { 10 | 11 | } 12 | 13 | export interface NotesListState { 14 | notes: Array; 15 | } 16 | 17 | export class NotesList extends React.Component { 18 | private applicationService: ApplicationService = ApplicationService.getInstance(); 19 | private eventBus: EventBusService = this.applicationService.getEventBus(); 20 | private globalNavigationService: GlobalNavigationService = this.applicationService.getGlobalNavigationService(); 21 | 22 | constructor(props: NotesListProps) { 23 | super(props); 24 | this.state = { 25 | notes: [] 26 | }; 27 | } 28 | 29 | componentDidMount(): void { 30 | this.setState({notes: this.applicationService.getAllNotes()}); 31 | } 32 | 33 | deleteNote(noteIndex: number): void { 34 | const notes: Array = this.state.notes.filter((note, index: number) => index !== noteIndex); 35 | this.setState({ 36 | notes 37 | }); 38 | this.applicationService.setNotes(notes); 39 | this.eventBus?.postMessage({name: "NotesCountUpdate", payload: {count: notes?.length}}); 40 | } 41 | 42 | navigateToNotesList(): void { 43 | this.globalNavigationService?.navigate(NavigationAlias.NOTES_LIST); 44 | } 45 | 46 | render(): React.ReactNode { 47 | return ( 48 |
49 | 50 | 55 | 56 | {!this.state.notes?.length ?

There is no notes

: ''} 57 | 58 | {this.state.notes?.map((note: Note, index: number) => { 59 | return ( 60 | 61 | 62 | {note.subject} 63 | {note.type} 64 | 65 | {note.body} 66 | 67 | 68 | 69 |
70 | 75 |
76 |
77 |
78 | ); 79 | })} 80 |
81 |
82 | ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /react-mfe1/src/app/index.less: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | } 4 | 5 | .switch-wrapper { 6 | position: relative; 7 | } 8 | 9 | .switch-wrapper > div { 10 | position: absolute; 11 | } 12 | 13 | .notes-admin-list { 14 | margin: 24px; 15 | } 16 | -------------------------------------------------------------------------------- /react-mfe1/src/app/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { hot } from 'react-hot-loader'; 3 | import './index.less'; 4 | import 'semantic-ui-css/semantic.min.css'; 5 | import {NotesList} from "app/components/notes-list"; 6 | import {ApplicationProps} from "../application"; 7 | import 'semantic-ui-css/semantic.min.css' 8 | import {Switch, Route, Redirect} from "react-router-dom"; 9 | 10 | export const App = hot(module)((props: ApplicationProps) => { 11 | return ( 12 |
13 |

{props.header}

14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | ); 22 | }) 23 | ; 24 | -------------------------------------------------------------------------------- /react-mfe1/src/app/models/event-bus.model.ts: -------------------------------------------------------------------------------- 1 | export type EventBusService = { 2 | readonly name: string; 3 | onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 4 | onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null; 5 | /** 6 | * Closes the BroadcastChannel object, opening it up to garbage collection. 7 | */ 8 | close(): void; 9 | /** 10 | * Sends the given message to other BroadcastChannel objects set up for this channel. Messages can be structured objects, e.g. nested objects and arrays. 11 | */ 12 | postMessage(message: any): void; 13 | addEventListener(type: string, listener: (this: BroadcastChannel, ev: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void; 14 | removeEventListener(type: K, listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any, options?: boolean | EventListenerOptions): void; 15 | removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; 16 | } 17 | -------------------------------------------------------------------------------- /react-mfe1/src/app/models/global-navigation.model.ts: -------------------------------------------------------------------------------- 1 | import {NavigationAlias} from './navigation.const'; 2 | 3 | export type GlobalNavigationService = { 4 | navigate(routeAlias: NavigationAlias): void; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /react-mfe1/src/app/models/navigation.const.ts: -------------------------------------------------------------------------------- 1 | // TODO: move to lib 2 | export enum NavigationAlias { 3 | NOTES_ADMIN_PANEL = 'NOTES_ADMIN_PANEL', 4 | NOTES_LIST = 'NOTES_LIST' 5 | } 6 | -------------------------------------------------------------------------------- /react-mfe1/src/app/models/note.model.ts: -------------------------------------------------------------------------------- 1 | export type Note = { 2 | id: string; 3 | subject: string; 4 | body: string; 5 | type: string; 6 | } 7 | -------------------------------------------------------------------------------- /react-mfe1/src/application.service.ts: -------------------------------------------------------------------------------- 1 | import {EventBusService} from "app/models/event-bus.model"; 2 | import {Note} from "app/models/note.model"; 3 | import {GlobalNavigationService} from 'app/models/global-navigation.model'; 4 | 5 | export class ApplicationService { 6 | private static instance: ApplicationService; 7 | private eventBus: EventBusService 8 | private globalNavigationService: GlobalNavigationService; 9 | 10 | public static getInstance(): ApplicationService { 11 | if (!ApplicationService.instance) { 12 | ApplicationService.instance = new ApplicationService(); 13 | } 14 | return ApplicationService.instance; 15 | } 16 | 17 | setGlobalNavigationService(globalNavigationService: GlobalNavigationService | undefined): void { 18 | if(globalNavigationService) { 19 | this.globalNavigationService = globalNavigationService; 20 | } 21 | } 22 | 23 | getGlobalNavigationService(): GlobalNavigationService { 24 | return this.globalNavigationService; 25 | } 26 | 27 | setEventBus(eventBus: EventBusService | undefined): void { 28 | if (eventBus) { 29 | this.eventBus = eventBus; 30 | } 31 | } 32 | 33 | getEventBus(): EventBusService { 34 | return this.eventBus; 35 | } 36 | 37 | getAllNotes(): Array { 38 | let existingNotes: Array; 39 | const existingNotesString: string | null = window.localStorage.getItem("my_notes"); 40 | if (!existingNotesString) { 41 | existingNotes = []; 42 | } else { 43 | existingNotes = JSON.parse(existingNotesString); 44 | } 45 | return existingNotes; 46 | } 47 | 48 | setNotes(notes: Array): void { 49 | return window.localStorage.setItem("my_notes", JSON.stringify(notes)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /react-mfe1/src/application.tsx: -------------------------------------------------------------------------------- 1 | import {BrowserRouter} from "react-router-dom"; 2 | import {App} from "app/index"; 3 | import * as React from "react"; 4 | import {ApplicationService} from "./application.service"; 5 | import {EventBusService} from "app/models/event-bus.model"; 6 | import {GlobalNavigationService} from 'app/models/global-navigation.model'; 7 | 8 | export interface ApplicationProps { 9 | header?: string; 10 | eventBus?: EventBusService; 11 | globalNavigation?: GlobalNavigationService; 12 | basename?: string; 13 | } 14 | 15 | export class Application extends React.Component { 16 | private applicationService: ApplicationService = ApplicationService.getInstance(); 17 | 18 | constructor(props: ApplicationProps) { 19 | super(props); 20 | console.log(props); 21 | this.applicationService.setEventBus(this.props.eventBus); 22 | this.applicationService.setGlobalNavigationService(this.props.globalNavigation); 23 | } 24 | 25 | render(): React.ReactNode { 26 | return ( 27 | 28 | 29 | 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /react-mfe1/src/assets/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React module federation plugin 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /react-mfe1/src/main.plugin.js: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import {Application} from "./application"; 3 | 4 | export class MainApplicationPlugin extends React.Component { 5 | constructor(props) { 6 | super(props); 7 | } 8 | 9 | render() { 10 | console.log("REACT 1: " + this.props.basename); 11 | return ; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /react-mfe1/src/main.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import * as ReactDOM from 'react-dom'; 3 | import {Application} from "./application"; 4 | 5 | 6 | ReactDOM.render( 7 | , 8 | document.getElementById('root') 9 | ); 10 | -------------------------------------------------------------------------------- /react-mfe1/src/sitemap-builder.js: -------------------------------------------------------------------------------- 1 | require('babel-register'); 2 | 3 | const router = require('./router').default; 4 | const Sitemap = require('../').default; 5 | 6 | ( 7 | new Sitemap(router) 8 | .build('http://my-site.ru') 9 | .save('./sitemap.xml') 10 | ); 11 | -------------------------------------------------------------------------------- /react-mfe1/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "strictPropertyInitialization": false, 5 | "allowSyntheticDefaultImports": true, 6 | "allowJs": true, 7 | "target": "es5", 8 | "jsx": "react", 9 | "module": "esnext", 10 | "moduleResolution": "node", 11 | "experimentalDecorators": true, 12 | "declaration": false, 13 | "removeComments": true, 14 | "noImplicitReturns": true, 15 | "noUnusedLocals": true, 16 | "strict": true, 17 | "outDir": "build", 18 | "lib": ["es6", "es7", "dom", "es2015"], 19 | "baseUrl": "src", 20 | "paths": { 21 | "app/*": ["./app/*"] 22 | } 23 | }, 24 | "exclude": ["build", "node_modules", "server"] 25 | } 26 | -------------------------------------------------------------------------------- /react-mfe1/types/global.d.ts: -------------------------------------------------------------------------------- 1 | /** Global definitions for development **/ 2 | 3 | // for style loader 4 | declare module '*.css' { 5 | const styles: any; 6 | export = styles; 7 | } 8 | 9 | // Omit type https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046 10 | type Omit = Pick> 11 | type PartialPick = Partial & Pick; 12 | -------------------------------------------------------------------------------- /react-mfe1/types/react-redux.d.ts: -------------------------------------------------------------------------------- 1 | import 'react-redux'; 2 | import { ComponentType } from 'react'; 3 | 4 | declare module 'react-redux' { 5 | // Add removed inferrable type to support connect as decorator 6 | // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16652 7 | export interface InferableComponentDecorator { 8 | >(component: T): T; 9 | } 10 | 11 | // overload connect interface to return built-in ClassDecorator 12 | // https://github.com/reactjs/react-redux/pull/541#issuecomment-269197189 13 | export interface Connect { 14 | ( 15 | mapStateToProps: MapStateToPropsParam, 16 | mapDispatchToProps?: MapDispatchToPropsParam, 17 | mergeProps?: MergeProps, 18 | options?: Options 19 | ): InferableComponentDecorator; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /react-mfe2/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | insert_final_newline = false 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /react-mfe2/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | .DS_STORE 4 | node_modules 5 | .module-cache 6 | *.log* 7 | dist 8 | backup 9 | package-lock.json 10 | build/*.* -------------------------------------------------------------------------------- /react-mfe2/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "always", 3 | "semi": true, 4 | "useTabs": false, 5 | "tabWidth": 2, 6 | "bracketSpacing": true, 7 | "singleQuote": true, 8 | "jsxBracketSameLine": false, 9 | "printWidth": 100 10 | } 11 | -------------------------------------------------------------------------------- /react-mfe2/README.md: -------------------------------------------------------------------------------- 1 | # Frontend Boilerplate with React, Redux & TypeScript 2 | 3 | A bare minimum react-redux-webpack-typescript boilerplate with TodoMVC example. 4 | 5 | [Live demo](https://rokoroku.github.io/react-redux-typescript-boilerplate) 6 | 7 | Note that this project does not include **Server-Side Rendering**, **Static code analysis**, **Testing Frameworks** and other stuffs that makes the package unnecessarily complicated. (e.g. yarn, tslint, jest, ...) 8 | If needed, please fork this repository and add your own that meets your requirements. 9 | 10 | Ideal for creating React apps from the scratch. 11 | 12 | See also: [react-mobx-typescript-boilerplate](https://github.com/rokoroku/react-mobx-typescript-boilerplate) 13 | 14 | ## Contains 15 | 16 | - [x] [Typescript](https://www.typescriptlang.org/) 3 17 | - [x] [React](https://facebook.github.io/react/) 16.8 18 | - [x] [Redux](https://github.com/reactjs/redux) 4 19 | - [x] [React Router](https://github.com/ReactTraining/react-router) 4.3 20 | - [x] [Redux DevTools Extension](https://github.com/zalmoxisus/redux-devtools-extension) 21 | - [x] [TodoMVC example](http://todomvc.com) 22 | 23 | ### Build tools 24 | 25 | - [x] [Webpack](https://webpack.github.io) 4 26 | - [x] [Tree Shaking](https://medium.com/@Rich_Harris/tree-shaking-versus-dead-code-elimination-d3765df85c80) 27 | - [x] [Webpack Dev Server](https://github.com/webpack/webpack-dev-server) 28 | - [x] [Typescript Loader](https://github.com/TypeStrong/ts-loader) 29 | - [x] [PostCSS Loader](https://github.com/postcss/postcss-loader) 30 | - [x] [PostCSS Preset Env](https://preset-env.cssdb.org/) 31 | - [x] [CSS modules](https://github.com/css-modules/css-modules) 32 | - [x] [React Hot Loader](https://github.com/gaearon/react-hot-loader) 33 | - [x] [Mini CSS Extract Plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) 34 | - [x] [HTML Webpack Plugin](https://github.com/ampedandwired/html-webpack-plugin) 35 | 36 | ## Installation 37 | 38 | ``` 39 | $ npm ci 40 | ``` 41 | 42 | ## Running 43 | 44 | ``` 45 | $ npm start 46 | ``` 47 | 48 | ## Build 49 | 50 | ``` 51 | $ npm run build 52 | ``` 53 | 54 | ## Deploy (to the [GitHub Pages](https://pages.github.com/)) 55 | 56 | ``` 57 | $ npm run deploy 58 | ``` 59 | 60 | ## Format code (using [Prettier](https://github.com/prettier/prettier)) 61 | 62 | ``` 63 | $ npm run prettier 64 | ``` 65 | 66 | # License 67 | 68 | MIT 69 | -------------------------------------------------------------------------------- /react-mfe2/generate-react-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "usesTypeScript": true, 3 | "usesCssModule": true, 4 | "cssPreprocessor": "less", 5 | "testLibrary": "None", 6 | "component": { 7 | "default": { 8 | "path": "app/components", 9 | "withStyle": true, 10 | "withTest": true, 11 | "withStory": true, 12 | "withLazy": true 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /react-mfe2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fastener-shop-spa", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "predeploy": "npm run build", 7 | "deploy": "gh-pages -d build", 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "start": "webpack-cli serve", 10 | "build": "webpack --mode production", 11 | "prettier": "prettier --write \"src/**/*.{ts,tsx,css}\"", 12 | "server": "tsc-watch ./server/server.ts --outDir ./dist --onSuccess \"node ./dist/server.js\" --onFailure \"echo Beep! Compilation Failed\" --compiler typescript/bin/tsc", 13 | "startWithMock": "concurrently \"npm:server\" \"npm:start\"" 14 | }, 15 | "license": "MIT", 16 | "devDependencies": { 17 | "@babel/core": "^7.2.2", 18 | "@types/classnames": "^2.2.7", 19 | "@types/history": "^4.7.2", 20 | "@types/node": "^10.12.18", 21 | "@types/react": "^16.8.2", 22 | "@types/react-dom": "^16.8.0", 23 | "@types/react-router": "^4.4.3", 24 | "@types/react-router-dom": "^4.3.3", 25 | "@types/webpack": "^4.4.23", 26 | "@types/webpack-env": "1.13.6", 27 | "babel-loader": "^8.0.5", 28 | "body-parser": "^1.19.0", 29 | "concurrently": "^4.1.0", 30 | "css-loader": "^2.1.0", 31 | "express": "^4.16.4", 32 | "file-loader": "^3.0.1", 33 | "gh-pages": "^2.0.1", 34 | "html-loader": "^1.0.0-alpha.0", 35 | "html-webpack-plugin": "^4.0.0-alpha", 36 | "less": "2.7.2", 37 | "less-loader": "4.0.4", 38 | "mini-css-extract-plugin": "^0.5.0", 39 | "prettier": "^1.15.3", 40 | "react-hot-loader": "^4.6.3", 41 | "style-loader": "^0.23.1", 42 | "ts-loader": "^5.3.3", 43 | "tsc-watch": "^2.1.2", 44 | "typescript": "^3.7.5", 45 | "webpack": "5.36.2", 46 | "webpack-cleanup-plugin": "^0.5.1", 47 | "webpack-cli": "4.7.0", 48 | "webpack-dev-server": "3.11.2" 49 | }, 50 | "dependencies": { 51 | "@babel/preset-env": "^7.14.4", 52 | "@babel/preset-react": "^7.13.13", 53 | "axios": "^0.18.0", 54 | "gulp": "^4.0.2", 55 | "react": "^16.13.0", 56 | "react-dom": "^16.8.1", 57 | "react-router-dom": "^5.0.0" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /react-mfe2/src/app/components/props-plugin/props.component.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export class PropsComponent extends React.Component> { 4 | render() { 5 | return ( 6 |
7 | COUNT FROM PROPS: {this.props.count ?? 'Click the button above'} 8 |
9 | ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /react-mfe2/src/app/containers/first-route/about-container.less: -------------------------------------------------------------------------------- 1 | @import "../../main-styles/main"; 2 | @import "../../main-styles/variables"; 3 | @import "../../main-styles/colors"; 4 | 5 | .about-container { 6 | width: 100%; 7 | flex: 1; 8 | background-color: #2f3032; 9 | color: #0d71bb; 10 | font-size: 42px; 11 | display: flex; 12 | align-items: center; 13 | justify-content: center; 14 | } 15 | 16 | 17 | .third-route { 18 | width: 100%; 19 | flex: 1; 20 | background-color: #2f3032; 21 | color: #0d71bb; 22 | font-size: 42px; 23 | display: flex; 24 | flex-direction: column; 25 | align-items: center; 26 | justify-content: center; 27 | 28 | &__text { 29 | margin-bottom: 12px; 30 | } 31 | 32 | &__subtext { 33 | font-size: 24px; 34 | margin-top: 12px; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /react-mfe2/src/app/containers/first-route/about-container.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { Link, Redirect, Route, RouteComponentProps, Switch } from 'react-router-dom'; 3 | import {MainApp} from 'app/containers/main-container/main-container'; 4 | 5 | export namespace SecondRoute { 6 | export interface Props extends RouteComponentProps { 7 | } 8 | } 9 | 10 | export class SecondRoute extends React.Component { 11 | 12 | constructor(props: SecondRoute.Props, context?: any) { 13 | super(props, context); 14 | } 15 | 16 | componentDidMount(): void { 17 | console.log("DID MOUNT"); 18 | } 19 | 20 | componentDidUpdate(prevProps: Readonly, prevState: Readonly, snapshot?: any): void { 21 | console.log("DID UPDATE"); 22 | } 23 | 24 | componentWillUnmount(): void { 25 | console.log("WILL UNMOUNT"); 26 | } 27 | 28 | 29 | render() { 30 | const { location } = this.props; 31 | 32 | return ( 33 |
34 |
This is Second Route
35 |
36 | 37 | This is second level First Route inside Second route 38 | 39 | 40 | This is second level Second Route inside Second route 41 | 42 | 43 | This is second level Third Route inside Second route 44 | 45 |
46 | 47 | 48 |
Really this second level react router inside Angular app
49 |
50 | 51 |
OMG It works... O_o
52 |
53 | 54 |
Really, It`s awesome...
55 |
56 | 57 |
58 |
59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /react-mfe2/src/app/containers/main-container/main-container.less: -------------------------------------------------------------------------------- 1 | .fastener-application { 2 | background: linear-gradient(90deg, @bg-color (@dot-space - @dot-size), transparent 1%) center, 3 | linear-gradient(@bg-color (@dot-space - @dot-size), transparent 1%) center, 4 | @dot-color; 5 | background-size: @dot-space @dot-space; 6 | min-height: 100vh; 7 | display: flex; 8 | flex-direction: column; 9 | 10 | &__menu { 11 | display: flex; 12 | align-items: center; 13 | justify-content: center; 14 | background-color: #2f3032; 15 | width: 100%; 16 | } 17 | 18 | &__link { 19 | color: #0d71bb; 20 | font-size: 18px; 21 | margin: 8px; 22 | 23 | &:hover { 24 | color: white; 25 | } 26 | } 27 | 28 | &__mobile-menu { 29 | height: 100%; 30 | display: flex; 31 | flex-direction: column; 32 | justify-content: flex-start; 33 | 34 | &-sidebar { 35 | background: @active-color-main !important; 36 | } 37 | 38 | &-nav { 39 | 40 | &:last-child & { 41 | &-item { 42 | border-bottom: none; 43 | } 44 | } 45 | 46 | &-item { 47 | padding: 24px; 48 | color: #FFF; 49 | border-bottom: solid 1px #FFF; 50 | font-size: 16px; 51 | } 52 | } 53 | } 54 | } 55 | 56 | // Colors 57 | @bg-color: #FFFFFF; 58 | @dot-color: #919191; 59 | 60 | // Dimensions 61 | @dot-size: 1px; 62 | @dot-space: 22px; 63 | -------------------------------------------------------------------------------- /react-mfe2/src/app/containers/main-container/main-container.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { Link, Redirect, Route, Switch } from 'react-router-dom'; 3 | import { FirstRoute } from 'app/containers/second-component/contacts-container'; 4 | import { SecondRoute } from 'app/containers/first-route/about-container'; 5 | 6 | export namespace MainApp { 7 | export interface Props { 8 | } 9 | 10 | export interface State { 11 | } 12 | } 13 | 14 | export class MainApp extends React.Component { 15 | constructor(props: MainApp.Props, context?: any) { 16 | super(props, context); 17 | } 18 | 19 | render() { 20 | return ( 21 |
22 |
23 | 24 | This is First Route 25 | 26 | 27 | This is Second Route 28 | 29 | 30 | This is Third Route 31 | 32 |
33 | 34 | 35 | 36 | 37 |
This is Third Route
38 |
39 | 40 |
41 |
42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /react-mfe2/src/app/containers/second-component/contacts-container.less: -------------------------------------------------------------------------------- 1 | @import "../../main-styles/main"; 2 | @import "../../main-styles/variables"; 3 | @import "../../main-styles/colors"; 4 | 5 | .contacts-container { 6 | width: 100%; 7 | flex: 1; 8 | background-color: #2f3032; 9 | color: #0d71bb; 10 | font-size: 42px; 11 | display: flex; 12 | align-items: center; 13 | justify-content: center; 14 | 15 | &__submenu { 16 | display: flex; 17 | align-items: center; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /react-mfe2/src/app/containers/second-component/contacts-container.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | export namespace FirstRoute { 4 | export interface Props { 5 | } 6 | } 7 | 8 | export class FirstRoute extends React.Component { 9 | 10 | constructor(props: FirstRoute.Props, context?: any) { 11 | super(props, context); 12 | } 13 | 14 | render() { 15 | 16 | return ( 17 |
18 | This is first react route inside Angular app 19 |
20 | ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /react-mfe2/src/app/index.less: -------------------------------------------------------------------------------- 1 | @import "containers/main-container/main-container"; 2 | @import "containers/second-component/contacts-container"; 3 | @import "containers/first-route/about-container"; 4 | 5 | * { 6 | box-sizing: border-box; 7 | } 8 | 9 | .switch-wrapper { 10 | position: relative; 11 | } 12 | 13 | .switch-wrapper > div { 14 | position: absolute; 15 | } 16 | -------------------------------------------------------------------------------- /react-mfe2/src/app/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import {hot} from 'react-hot-loader'; 3 | import './index.less'; 4 | import {MainApp} from 'app/containers/main-container/main-container'; 5 | 6 | export const App = hot(module)((props: Record) => { 7 | console.dir(props); 8 | return ( 9 |
10 | 11 |
12 | ); 13 | }) 14 | ; 15 | -------------------------------------------------------------------------------- /react-mfe2/src/app/main-styles/colors.less: -------------------------------------------------------------------------------- 1 | @background-color-main: #fff; 2 | @text-hover-color: #fff; 3 | @category-item-border-color: #c9c9c9; 4 | @active-color-main: rgb(244, 121, 32); 5 | @dark-grey: #878787; 6 | @black: #000000; 7 | -------------------------------------------------------------------------------- /react-mfe2/src/app/main-styles/main.less: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | margin: 0; 4 | padding: 0; 5 | } 6 | 7 | body { 8 | background: #f5f5f5; 9 | -webkit-font-smoothing: antialiased; 10 | -moz-font-smoothing: antialiased; 11 | -ms-font-smoothing: antialiased; 12 | font-smoothing: antialiased; 13 | min-width: 450px; 14 | } 15 | 16 | button, 17 | input[type='checkbox'] { 18 | outline: none; 19 | } 20 | -------------------------------------------------------------------------------- /react-mfe2/src/app/main-styles/variables.less: -------------------------------------------------------------------------------- 1 | @full-width: 1200px; 2 | 3 | @headerHeight: 100px; 4 | @footerHeight: 250px; 5 | @fakeHeaderMargin: 24px; 6 | @bottomShopMargin: 64px; 7 | 8 | @dots-size: 4px; 9 | 10 | @mobileScreenWidth: 900px; 11 | -------------------------------------------------------------------------------- /react-mfe2/src/app/routes.ts: -------------------------------------------------------------------------------- 1 | export const RestRoutes: Record = { 2 | getObject: '/rest/getObject', 3 | objectTypes: '/rest/getObjectTypes', 4 | attributes: '/rest/getAttributes', 5 | attribute: '/rest/attribute', 6 | filterAttributes: '/rest/filterAttributesByObject', 7 | objectType: '/rest/objectType', 8 | objects: "/rest/getObjects", 9 | object: "/rest/object", 10 | news: "/rest/news", 11 | new: "/rest/new" 12 | }; 13 | -------------------------------------------------------------------------------- /react-mfe2/src/assets/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React example plugin 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /react-mfe2/src/main.plugin.js: -------------------------------------------------------------------------------- 1 | import { BrowserRouter } from 'react-router-dom'; 2 | import { App } from 'app/index'; 3 | import * as React from 'react'; 4 | 5 | export class MainApplicationPlugin extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | } 9 | 10 | render() { 11 | console.log("REACT 2: " + this.props.basename); 12 | return ( 13 | 14 | 15 | 16 | ) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /react-mfe2/src/main.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import * as ReactDOM from 'react-dom'; 3 | import { BrowserRouter as Router } from 'react-router-dom'; 4 | import { App } from './app'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | 10 | 11 | , 12 | document.getElementById('root') 13 | ); 14 | -------------------------------------------------------------------------------- /react-mfe2/src/props.plugin.js: -------------------------------------------------------------------------------- 1 | import {App} from 'app/index'; 2 | import * as React from 'react'; 3 | import {PropsComponent} from "app/components/props-plugin/props.component"; 4 | 5 | export class PluginApplication extends React.Component { 6 | constructor(props) { 7 | super(props); 8 | } 9 | 10 | render() { 11 | return ( 12 |
13 | 14 |
15 | ) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /react-mfe2/src/sitemap-builder.js: -------------------------------------------------------------------------------- 1 | require('babel-register'); 2 | 3 | const router = require('./router').default; 4 | const Sitemap = require('../').default; 5 | 6 | ( 7 | new Sitemap(router) 8 | .build('http://my-site.ru') 9 | .save('./sitemap.xml') 10 | ); 11 | -------------------------------------------------------------------------------- /react-mfe2/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "strictPropertyInitialization": false, 5 | "allowSyntheticDefaultImports": true, 6 | "allowJs": true, 7 | "target": "es5", 8 | "jsx": "react", 9 | "module": "esnext", 10 | "moduleResolution": "node", 11 | "experimentalDecorators": true, 12 | "declaration": false, 13 | "removeComments": true, 14 | "noImplicitReturns": true, 15 | "noUnusedLocals": true, 16 | "strict": true, 17 | "outDir": "build", 18 | "lib": ["es6", "es7", "dom", "es2015"], 19 | "baseUrl": "src", 20 | "paths": { 21 | "app/*": ["./app/*"] 22 | } 23 | }, 24 | "exclude": ["build", "node_modules", "server"] 25 | } 26 | -------------------------------------------------------------------------------- /react-mfe2/types/global.d.ts: -------------------------------------------------------------------------------- 1 | /** Global definitions for development **/ 2 | 3 | // for style loader 4 | declare module '*.css' { 5 | const styles: any; 6 | export = styles; 7 | } 8 | -------------------------------------------------------------------------------- /vue-mfe1/index.html: -------------------------------------------------------------------------------- 1 |
2 | -------------------------------------------------------------------------------- /vue-mfe1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@vue3-demo/home", 3 | "private": true, 4 | "version": "1.0.0", 5 | "scripts": { 6 | "start": "webpack-cli serve", 7 | "serve": "serve dist -p 3002", 8 | "build": "webpack --mode production", 9 | "clean": "rm -rf dist" 10 | }, 11 | "dependencies": { 12 | "@babel/core": "^7.11.0", 13 | "@vue/compiler-sfc": "3.2.6", 14 | "babel-loader": "^8.1.0", 15 | "serve": "^12.0.0", 16 | "vue": "^3.0.11", 17 | "vue-router": "4.0.11" 18 | }, 19 | "devDependencies": { 20 | "@vue/compiler-sfc": "3.2.6", 21 | "css-loader": "6.2.0", 22 | "file-loader": "6.2.0", 23 | "html-webpack-plugin": "5.3.2", 24 | "mini-css-extract-plugin": "2.3.0", 25 | "url-loader": "4.1.1", 26 | "vue-loader": "16.5.0", 27 | "webpack": "5.52.1", 28 | "webpack-cli": "4.8.0", 29 | "webpack-dev-server": "4.2.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vue-mfe1/src/App.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 83 | 84 | 99 | -------------------------------------------------------------------------------- /vue-mfe1/src/bootstrapFunction.js: -------------------------------------------------------------------------------- 1 | import {createApp} from "vue"; 2 | import App from "./App" 3 | import User from "./components/User"; 4 | import UserProfile from "./components/UserProfile"; 5 | import UserPosts from "./components/UserPosts"; 6 | import {createRouter, createMemoryHistory, createWebHistory} from "vue-router"; 7 | 8 | 9 | const routes = [ 10 | { 11 | path: '/user/:id', 12 | component: User, 13 | children: [ 14 | { 15 | path: 'profile', 16 | component: UserProfile, 17 | }, 18 | { 19 | path: 'posts', 20 | component: UserPosts, 21 | }, 22 | ], 23 | }, 24 | ] 25 | 26 | 27 | export default (refElement, props, base) => { 28 | const router = createRouter({ 29 | history: createWebHistory(base), 30 | routes 31 | }) 32 | const app = createApp(App, { 33 | data: () => { 34 | return (this.props || {}); 35 | } 36 | }); 37 | app.use(router); 38 | app.mount(refElement); 39 | } 40 | -------------------------------------------------------------------------------- /vue-mfe1/src/components/Button.js: -------------------------------------------------------------------------------- 1 | import { render, h } from "vue"; 2 | const button = { 3 | name: "btn-component", 4 | render() { 5 | return h( 6 | "button", 7 | { 8 | id: "btn-primary", 9 | }, 10 | "Hello World" 11 | ); 12 | }, 13 | }; 14 | export default button; 15 | -------------------------------------------------------------------------------- /vue-mfe1/src/components/Content.vue: -------------------------------------------------------------------------------- 1 | 4 | 13 | -------------------------------------------------------------------------------- /vue-mfe1/src/components/User.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 73 | 74 | 77 | -------------------------------------------------------------------------------- /vue-mfe1/src/components/UserPosts.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 72 | 73 | 76 | -------------------------------------------------------------------------------- /vue-mfe1/src/components/UserProfile.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 76 | 77 | 80 | -------------------------------------------------------------------------------- /vue-mfe1/src/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-isupov/multi-framework-module-federation/a80b7c7010ad21ae99c4645a41ce6502a2cb9138/vue-mfe1/src/logo.png -------------------------------------------------------------------------------- /vue-mfe1/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from "vue"; 2 | import App from "./App.vue"; 3 | import User from "./components/User"; 4 | import UserProfile from "./components/UserProfile"; 5 | import UserPosts from "./components/UserPosts" 6 | import {createWebHistory, createRouter, createMemoryHistory} from "vue-router"; 7 | 8 | 9 | 10 | const routes = [ 11 | { 12 | path: '/user/:id', 13 | component: User, 14 | children: [ 15 | { 16 | path: 'profile', 17 | component: UserProfile, 18 | }, 19 | { 20 | path: 'posts', 21 | component: UserPosts, 22 | }, 23 | ], 24 | }, 25 | ] 26 | 27 | const router = createRouter({ 28 | history: createWebHistory(), 29 | routes 30 | }) 31 | 32 | 33 | const app = createApp(App); 34 | app.use(router) 35 | app.mount("#app"); 36 | -------------------------------------------------------------------------------- /vue-mfe1/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const { VueLoaderPlugin } = require("vue-loader"); 3 | const MiniCssExtractPlugin = require("mini-css-extract-plugin"); 4 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 5 | const { ModuleFederationPlugin } = require("webpack").container; 6 | module.exports = (env = {}) => ({ 7 | mode: "development", 8 | cache: false, 9 | devtool: "source-map", 10 | optimization: { 11 | minimize: false, 12 | }, 13 | target: "web", 14 | entry: path.resolve(__dirname, "./src/main.js"), 15 | // output: { 16 | // path: path.resolve(__dirname, './dist'), 17 | // publicPath: '/dist/' 18 | // }, 19 | output: { 20 | publicPath: "auto", 21 | }, 22 | resolve: { 23 | extensions: [".vue", ".jsx", ".js", ".json"], 24 | alias: { 25 | // this isn't technically needed, since the default `vue` entry for bundlers 26 | // is a simple `export * from '@vue/runtime-dom`. However having this 27 | // extra re-export somehow causes webpack to always invalidate the module 28 | // on the first HMR update and causes the page to reload. 29 | vue: "@vue/runtime-dom", 30 | }, 31 | }, 32 | module: { 33 | rules: [ 34 | { 35 | test: /\.vue$/, 36 | use: "vue-loader", 37 | }, 38 | { 39 | test: /\.png$/, 40 | use: { 41 | loader: "url-loader", 42 | options: { limit: 8192 }, 43 | }, 44 | }, 45 | { 46 | test: /\.css$/, 47 | use: [ 48 | { 49 | loader: MiniCssExtractPlugin.loader, 50 | options: {}, 51 | }, 52 | "css-loader", 53 | ], 54 | }, 55 | ], 56 | }, 57 | plugins: [ 58 | new MiniCssExtractPlugin({ 59 | filename: "[name].css", 60 | }), 61 | new ModuleFederationPlugin({ 62 | name: "vue_app", 63 | filename: "remoteEntry.js", 64 | exposes: { 65 | "./Content": "./src/components/Content", 66 | "./Button": "./src/components/Button", 67 | "./App": "./src/bootstrapFunction", 68 | }, 69 | }), 70 | new HtmlWebpackPlugin({ 71 | template: path.resolve(__dirname, "./index.html"), 72 | }), 73 | new VueLoaderPlugin(), 74 | ], 75 | devServer: { 76 | static: { 77 | directory: path.join(__dirname), 78 | }, 79 | compress: true, 80 | port: 3002, 81 | hot: true, 82 | headers: { 83 | "Access-Control-Allow-Origin": "*", 84 | "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS", 85 | "Access-Control-Allow-Headers": 86 | "X-Requested-With, content-type, Authorization", 87 | }, 88 | }, 89 | }); 90 | --------------------------------------------------------------------------------