├── .gitignore ├── LICENSE ├── README.md ├── micro-frontend-app-orders ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── bundles-load.png ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.scss │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── core │ │ │ └── services │ │ │ │ └── navigation.service.ts │ │ ├── details-info │ │ │ ├── details-info-routing.module.ts │ │ │ ├── details-info.component.html │ │ │ ├── details-info.component.scss │ │ │ ├── details-info.component.ts │ │ │ └── details-info.module.ts │ │ ├── details-shipping │ │ │ ├── details-shipping-routing.module.ts │ │ │ ├── details-shipping.component.html │ │ │ ├── details-shipping.component.scss │ │ │ ├── details-shipping.component.ts │ │ │ └── details-shipping.module.ts │ │ ├── order-details │ │ │ ├── order-details-routing.module.ts │ │ │ ├── order-details.component.html │ │ │ ├── order-details.component.scss │ │ │ ├── order-details.component.ts │ │ │ └── order-details.module.ts │ │ ├── order-list │ │ │ ├── models │ │ │ │ └── order-list-element.model.ts │ │ │ ├── order-list-routing.module.ts │ │ │ ├── order-list.component.html │ │ │ ├── order-list.component.scss │ │ │ ├── order-list.component.ts │ │ │ ├── order-list.module.ts │ │ │ └── services │ │ │ │ └── order-list.service.ts │ │ ├── orders │ │ │ ├── orders-routing.module.ts │ │ │ ├── orders.component.html │ │ │ ├── orders.component.scss │ │ │ ├── orders.component.ts │ │ │ └── orders.module.ts │ │ └── shared │ │ │ └── .gitkeep │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json └── webpack.extra.js ├── micro-frontend-envelope ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── copy-bundles.js ├── copy-wc-polyfills.js ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.scss │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── core │ │ │ └── .gitkeep │ │ ├── dashboard │ │ │ ├── dashboard-routing.module.ts │ │ │ ├── dashboard.component.html │ │ │ ├── dashboard.component.scss │ │ │ ├── dashboard.component.ts │ │ │ └── dashboard.module.ts │ │ ├── envelope │ │ │ ├── component │ │ │ │ ├── micro-app │ │ │ │ │ └── micro-app.component.ts │ │ │ │ └── nav │ │ │ │ │ ├── nav.component.html │ │ │ │ │ ├── nav.component.scss │ │ │ │ │ └── nav.component.ts │ │ │ ├── envelope-routing.module.ts │ │ │ ├── envelope.component.html │ │ │ ├── envelope.component.ts │ │ │ └── envelope.module.ts │ │ └── shared │ │ │ └── .gitkeep │ ├── assets │ │ └── .gitignore │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.scss │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json ├── tslint.json ├── webpack.bundle.aws.extra.js ├── webpack.bundle.extra.js └── webpack.extra.js ├── prepare-sources-s3.sh └── showcase.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /**/dist 3 | /**/tmp 4 | /**/out-tsc 5 | /**/target 6 | /static 7 | 8 | # logs 9 | /**/logs 10 | 11 | # dependencies 12 | /**/node_modules 13 | 14 | # profiling files 15 | chrome-profiler-events.json 16 | speed-measure-plugin.json 17 | 18 | # IDEs and editors 19 | /.idea 20 | .project 21 | .classpath 22 | .c9/ 23 | *.launch 24 | .settings/ 25 | *.sublime-workspace 26 | *.iml 27 | .history/ 28 | 29 | # IDE - VSCode 30 | .vscode/* 31 | !.vscode/settings.json 32 | !.vscode/tasks.json 33 | !.vscode/launch.json 34 | !.vscode/extensions.json 35 | 36 | # misc 37 | /.sass-cache 38 | /connect.lock 39 | /coverage 40 | /libpeerconnection.log 41 | npm-debug.log 42 | yarn-error.log 43 | testem.log 44 | /typings 45 | 46 | # System Files 47 | .DS_Store 48 | Thumbs.db 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Bartosz Magryś 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Micro-app frontend architecture (experimental) examples and templates of various approaches 2 | ============================================================================ 3 | 4 | [![Join the chat at https://gitter.im/micro-frontend-architecture/community](https://badges.gitter.im/micro-frontend-architecture/community.svg)](https://gitter.im/micro-frontend-architecture/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | 6 | At this moment, this example consists of a few Angular projects demonstrating 7 | an implementation of a main application called Envelope and micro applications 8 | that can be attached not only at the build time (micro application as a _feature library_), 9 | but above all, dynamically at runtime (from external sources eg. CDN, dedicated gateway). 10 | 11 | The business case used as an example here is Administration Panel for an E-commerce system. 12 | 13 | Example consists of following projects: 14 | - Envelope `/micro-frontend-envelope`: Starting application with layout and main navigation that aggregates other apps. That's entry layer for every nested content in panel [(read more)](./micro-frontend-envelope/README.md), 15 | - Orders `/micro-frontend-app-orders`: Demo micro application which acts as Orders section 16 | - Micro-app model where bundles can be hosted separately and referenced at runtime in Envelope app [(read more)](./micro-frontend-app-orders/README.md), 17 | - (more coming soon) 18 | 19 | ![](showcase.gif) 20 | 21 | --- 22 | #### Assumptions 23 | 24 | - **No coupling with external frameworks and libraries dedicated 25 | to micro-frontend architecture**, 26 | - The quality of the micro application code shouldn't be drastically reduced 27 | due to the adaptation to the technology used to attach micro applications to 28 | the envelope application. 29 | - Micro applications can't be (very) toughly coupled to the technologies used 30 | only for attaching them to envelope. They should be easy to rewrite 31 | to a traditional model in case of problems with architecture. Developing such 32 | apps shouldn't be a one-way ticket. 33 | 34 | --- 35 | #### Potential use cases / Pros / Cons 36 | 37 | - Multi-domain, big projects, especially if multiple teams are working on 38 | separate, complicated domains or are skilled in different technologies 39 | (Angular / React / Vue.js), 40 | - Frequently changing website content, driven by A/B tests or AI decisions, 41 | when replacement at runtime has more pros compared to building dedicated release bundles 42 | and lets deliver features faster 43 | - Web content management systems (CMSs/WCMSs) 44 | 45 | Pros and cons differs depending on which exact micro-frontend model is used. 46 | They are listed in concrete projects. 47 | 48 | --- 49 | #### All technologies and tools used across projects 50 | 51 | - Newest [Angular 8](https://angular.io/) 52 | - Going beyond typical use cases of [Angular Elements](https://angular.io/guide/elements) 53 | - Envelope and all micro applications compatible with [Lazy Loading Feature Modules](https://angular.io/guide/lazy-loading-ngmodules) 54 | and [Angular Routing & Navigation](https://angular.io/guide/router) 55 | - Extended Angular CLI possibilities without ejecting thanks to [ngx-build-plus](https://github.com/manfredsteyer/ngx-build-plus) 56 | - [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) 57 | 58 | --- 59 | #### Setup / Usage / How to 60 | 61 | In every project: 62 | 63 | ``` 64 | npm install 65 | ``` 66 | 67 | Development of Envelope or any single micro application can be independent and easy as default: 68 | 69 | ``` 70 | npm run start 71 | ``` 72 | 73 | To run all together: 74 | 75 | 1. Build and host bundles of every micro app that you want to test: 76 | 77 | ``` 78 | npm run build 79 | npm run server 80 | ``` 81 | 82 | 2. Serve or build Envelope application: 83 | 84 | For development and live-reload: 85 | 86 | ``` 87 | npm run start 88 | ``` 89 | 90 | Production: 91 | 92 | ``` 93 | npm run bundle 94 | npm run server 95 | ``` 96 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/.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 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/.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 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/README.md: -------------------------------------------------------------------------------- 1 | Orders 2 | ============================================================================================== 3 | 4 | ### Fully functional Angular app as Web Component / Custom Element 5 | 6 | Can be hosted separately and referenced at runtime in Envelope app. 7 | 8 | --- 9 | #### Technologies and tools used 10 | 11 | - [Angular](https://angular.io/) with use of [Angular Elements](https://angular.io/guide/elements) 12 | - [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) 13 | - [ngx-build-plus](https://github.com/manfredsteyer/ngx-build-plus) 14 | 15 | Current status: 16 | - :heavy_check_mark: Angular 8 17 | - :heavy_check_mark: Lazy loading 18 | - :heavy_check_mark: Lightweight bundles, size of micro app reduced to minimum 19 | 20 |
21 | Details 22 | 23 | Date: 2019-06-17T17:43:28.547Z 24 | Hash: 0cbd6d10ab88118ad039 25 | Time: 6103ms 26 | chunk {0} main-es5.js (main) 9.22 kB [entry] [rendered] 27 | chunk {1} 1-es5.js () 3.48 kB [rendered] 28 | chunk {2} 2-es5.js () 2.37 kB [rendered] 29 | chunk {3} 3-es5.js () 4.29 kB [rendered] 30 | chunk {4} 4-es5.js () 4.29 kB [rendered] 31 | chunk {5} 5-es5.js () 1.91 kB [rendered] 32 | chunk {scripts} scripts.js (scripts) 13.3 kB [entry] [rendered] 33 | 34 | Date: 2019-06-17T17:43:32.376Z 35 | Hash: bd37670c2c0d70a4f024 36 | Time: 3803ms 37 | chunk {0} main-es2015.js (main) 9.11 kB [entry] [rendered] 38 | chunk {1} 1-es2015.js () 3.4 kB [rendered] 39 | chunk {2} 2-es2015.js () 2.29 kB [rendered] 40 | chunk {3} 3-es2015.js () 4.16 kB [rendered] 41 | chunk {4} 4-es2015.js () 4.15 kB [rendered] 42 | chunk {5} 5-es2015.js () 1.77 kB [rendered] 43 | chunk {scripts} scripts.js (scripts) 13.3 kB [entry] [rendered] 44 | 45 | ![image](bundles-load.png) 46 |
47 | 48 | - :heavy_check_mark: Angular router fully working (:grey_exclamation: with additional boilerplate) 49 | - :x: Ivy compiler [[not supported yet]](https://github.com/angular/angular/issues/30262#issuecomment-497101996) 50 | 51 | --- 52 | #### Pros: 53 | 54 | - Tiny, small projects where business cases / domains are separated 55 | (let's say, some kind of microservices on frontend), 56 | - Fast, independent builds and feature delivery 57 | - Blazing fast deployment of micro application, 58 | - Much less conflicts comparing to one monolith app developed by multiple teams, 59 | - Content not loaded, until used (lazy loading of micro applications / components, 60 | regardless of the technologies used inside), 61 | - Easier to remove from the entire system, easier to transfer to another, 62 | - Complexity of whole frontend project scales more horizontally instead of vertically, 63 | - Angular is not an only option. 64 | 65 | #### Cons: 66 | 67 | - Can be sometimes too coupled to Web Component / Angular Elements specifics, 68 | - Boilerplate in every app to handle architecture and navigation 69 | (Angular Router is not ready for that case out of the box), 70 | - Requires maintenance of additional Envelope app and shared services, guards etc. 71 | which is sometimes barely related to business cases, can be time-consuming 72 | and hard to debug, 73 | - The less people work on the whole solution, the less it pays off, 74 | - Too complex and over-designed solution if whole application and business 75 | cases are quite simple. 76 | 77 | --- 78 | #### Setup / Usage / How to 79 | 80 | ###### Development server 81 | 82 | Run `npm run start` for a dev server. Navigate to `http://localhost:4201/`. 83 | The app will automatically reload if you change any of the source files. 84 | You can also test production setup running `npm run start:prod` 85 | 86 | ###### Build 87 | 88 | Run `npm run build` to build the project. 89 | The build artifacts will be stored in the `dist/` directory. 90 | Use `npm run build:aws` if you are hosting micro app just at different context (not domain) 91 | or if are using some kind of gateway also for frontend assets and relative request path contexts are forwarded 92 | deep into the infrastructure. 93 | 94 | ###### Serve production build statics 95 | 96 | Run `npm run server` 97 | 98 | ###### Running unit tests 99 | 100 | Run `npm run test` to execute the unit tests via [Karma](https://karma-runner.github.io). 101 | 102 | ###### Running end-to-end tests 103 | 104 | Run `npm run e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 105 | 106 | --- 107 | #### Areas for improvements 108 | 109 | - The less boilerplate and coupled to WC code the better 110 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "micro-frontend-app-orders": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "ngx-build-plus:browser", 19 | "options": { 20 | "outputPath": "dist/micro-frontend-app-orders", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": false, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "src/styles.scss" 32 | ], 33 | "scripts": [ 34 | "node_modules/document-register-element/build/document-register-element.js" 35 | ] 36 | }, 37 | "configurations": { 38 | "production": { 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ], 45 | "optimization": true, 46 | "outputHashing": "none", 47 | "sourceMap": false, 48 | "extractCss": true, 49 | "namedChunks": false, 50 | "aot": true, 51 | "extractLicenses": true, 52 | "vendorChunk": false, 53 | "buildOptimizer": true, 54 | "budgets": [ 55 | { 56 | "type": "initial", 57 | "maximumWarning": "2mb", 58 | "maximumError": "5mb" 59 | } 60 | ] 61 | } 62 | } 63 | }, 64 | "serve": { 65 | "builder": "ngx-build-plus:dev-server", 66 | "options": { 67 | "browserTarget": "micro-frontend-app-orders:build" 68 | }, 69 | "configurations": { 70 | "production": { 71 | "browserTarget": "micro-frontend-app-orders:build:production" 72 | } 73 | } 74 | }, 75 | "extract-i18n": { 76 | "builder": "@angular-devkit/build-angular:extract-i18n", 77 | "options": { 78 | "browserTarget": "micro-frontend-app-orders:build" 79 | } 80 | }, 81 | "test": { 82 | "builder": "@angular-devkit/build-angular:karma", 83 | "options": { 84 | "main": "src/test.ts", 85 | "polyfills": "src/polyfills.ts", 86 | "tsConfig": "tsconfig.spec.json", 87 | "karmaConfig": "karma.conf.js", 88 | "assets": [ 89 | "src/favicon.ico", 90 | "src/assets" 91 | ], 92 | "styles": [ 93 | "src/styles.scss" 94 | ], 95 | "scripts": [] 96 | } 97 | }, 98 | "lint": { 99 | "builder": "@angular-devkit/build-angular:tslint", 100 | "options": { 101 | "tsConfig": [ 102 | "tsconfig.app.json", 103 | "tsconfig.spec.json", 104 | "e2e/tsconfig.json" 105 | ], 106 | "exclude": [ 107 | "**/node_modules/**" 108 | ] 109 | } 110 | }, 111 | "e2e": { 112 | "builder": "@angular-devkit/build-angular:protractor", 113 | "options": { 114 | "protractorConfig": "e2e/protractor.conf.js", 115 | "devServerTarget": "micro-frontend-app-orders:serve" 116 | }, 117 | "configurations": { 118 | "production": { 119 | "devServerTarget": "micro-frontend-app-orders:serve:production" 120 | } 121 | } 122 | } 123 | } 124 | }}, 125 | "defaultProject": "micro-frontend-app-orders" 126 | } 127 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/browserslist: -------------------------------------------------------------------------------- 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 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /micro-frontend-app-orders/bundles-load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/bundles-load.png -------------------------------------------------------------------------------- /micro-frontend-app-orders/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 } = 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 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /micro-frontend-app-orders/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 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', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to micro-frontend-app-orders!'); 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 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/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-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/micro-frontend-app-orders'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "micro-frontend-app-orders", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --port 4201", 7 | "start:prod": "ng serve --port 4201 --aot --prod=true --vendor-chunk=false --optimization=true", 8 | "build": "ng build --prod --extraWebpackConfig webpack.extra.js --single-bundle true --deploy-url http://localhost:8201/micro-frontend-app-orders/", 9 | "build:aws": "ng build --prod --extraWebpackConfig webpack.extra.js --single-bundle true --deploy-url micro-frontend-app-orders/", 10 | "server": "http-server dist -p 8201 --cors http://localhost:4200", 11 | "test": "ng test", 12 | "lint": "ng lint", 13 | "e2e": "ng e2e" 14 | }, 15 | "private": true, 16 | "dependencies": { 17 | "@angular/animations": "~8.0.0", 18 | "@angular/common": "~8.0.0", 19 | "@angular/compiler": "~8.0.0", 20 | "@angular/core": "~8.0.0", 21 | "@angular/elements": "~8.0.0", 22 | "@angular/forms": "~8.0.0", 23 | "@angular/platform-browser": "~8.0.0", 24 | "@angular/platform-browser-dynamic": "~8.0.0", 25 | "@angular/router": "~8.0.0", 26 | "document-register-element": "^1.13.2", 27 | "rxjs": "~6.4.0", 28 | "tslib": "^1.9.0", 29 | "zone.js": "~0.9.1" 30 | }, 31 | "devDependencies": { 32 | "@angular-devkit/build-angular": "~0.800.0", 33 | "@angular/cli": "~8.0.2", 34 | "@angular/compiler-cli": "~8.0.0", 35 | "@angular/language-service": "~8.0.0", 36 | "@types/jasmine": "~3.3.8", 37 | "@types/jasminewd2": "~2.0.3", 38 | "@types/node": "~8.9.4", 39 | "codelyzer": "^5.0.0", 40 | "http-server": "^0.11.1", 41 | "jasmine-core": "~3.4.0", 42 | "jasmine-spec-reporter": "~4.2.1", 43 | "karma": "~4.1.0", 44 | "karma-chrome-launcher": "~2.2.0", 45 | "karma-coverage-istanbul-reporter": "~2.0.1", 46 | "karma-jasmine": "~2.0.1", 47 | "karma-jasmine-html-reporter": "^1.4.0", 48 | "ngx-build-plus": "^8.0.3", 49 | "protractor": "~5.4.0", 50 | "ts-node": "~7.0.0", 51 | "tslint": "~5.15.0", 52 | "typescript": "~3.4.3" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { environment } from '../environments/environment'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: environment.APP_URL, 8 | loadChildren: () => import('./orders/orders.module').then(m => m.OrdersModule), 9 | }, 10 | // Render nothing if navigation goes to other app 11 | { 12 | path: '**', 13 | children: [], 14 | }, 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forRoot(routes, { useHash: true })], 19 | exports: [RouterModule], 20 | }) 21 | export class AppRoutingModule { 22 | } 23 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | //table.clickable-rows { 2 | // tr { 3 | // cursor: pointer; 4 | // } 5 | //} 6 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, 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 | 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.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'micro-frontend-app-orders'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('micro-frontend-app-orders'); 27 | }); 28 | 29 | it('should render title in a h1 tag', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to micro-frontend-app-orders!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Location } from '@angular/common'; 2 | import { Component, OnInit } from '@angular/core'; 3 | import { Router } from '@angular/router'; 4 | import { environment } from '../environments/environment'; 5 | import { NavigationService } from './core/services/navigation.service'; 6 | 7 | @Component({ 8 | selector: 'app-micro-frontend-orders-root', 9 | templateUrl: './app.component.html', 10 | styleUrls: ['./app.component.scss'], 11 | }) 12 | export class AppComponent implements OnInit { 13 | private readonly previousUrl: string; 14 | 15 | constructor(private readonly router: Router, 16 | private readonly location: Location, 17 | private readonly navigationService: NavigationService) { 18 | this.previousUrl = this.navigationService.getLastSuccessfulNavigationUrl(); 19 | } 20 | 21 | public ngOnInit(): void { 22 | this.router.initialNavigation(); 23 | 24 | // In development we should ignore global navigation problems and navigate to App URL 25 | if (!environment.production && this.router.url.length <= 1) { 26 | this.router.navigate([environment.APP_URL]); 27 | return; 28 | } 29 | 30 | // Uncomment to see tracing 31 | // console.log(`[Orders] Router URL: ${ this.router.url }, Last successful: ${ this.previousUrl },` 32 | // + ` Location: ${ this.location.path() }`); 33 | 34 | // If application has been initialized before and ever occurred successful navigation 35 | if (!!this.previousUrl) { 36 | // Case when we are back from other application (router URL is currently set as URL from other application) 37 | if (this.router.url !== this.previousUrl) { 38 | // Uncomment to see tracing 39 | // console.log('[Orders]', 'AppComponent', 'Navigating to the last successful navigation / component in app!'); 40 | 41 | this.router.navigate([this.previousUrl]); 42 | 43 | // Case when we navigate by routerLink in Envelope app 44 | } else if (this.previousUrl !== this.location.path() && this.previousUrl.startsWith(this.location.path())) { 45 | // Uncomment to see tracing 46 | // console.log('[Orders]', 'AppComponent', 'Updating browser URL to current navigation / component in app!'); 47 | 48 | // Use @angular/common#Location, do not use window.history! 49 | this.location.replaceState(this.previousUrl); 50 | } 51 | } 52 | 53 | // Resetting also works, but will be used in next micro application 54 | // this.router.navigate([this.location.path()], { skipLocationChange: true }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { DoBootstrap, Injector, NgModule } from '@angular/core'; 2 | import { createCustomElement } from '@angular/elements'; 3 | import { BrowserModule } from '@angular/platform-browser'; 4 | import { NavigationEnd, Router } from '@angular/router'; 5 | import { environment } from '../environments/environment'; 6 | 7 | import { AppRoutingModule } from './app-routing.module'; 8 | import { AppComponent } from './app.component'; 9 | import { NavigationService } from './core/services/navigation.service'; 10 | 11 | @NgModule({ 12 | declarations: [ 13 | AppComponent, 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | AppRoutingModule, 18 | ], 19 | providers: [], 20 | entryComponents: [AppComponent], 21 | }) 22 | export class AppModule implements DoBootstrap { 23 | constructor(private readonly injector: Injector, 24 | private readonly navigationService: NavigationService, 25 | private readonly router: Router) { 26 | // Module will never be implicitly destroyed, so there we can save all Router events 27 | this.router.events.subscribe((event: any) => { 28 | if (event instanceof NavigationEnd) { 29 | // Catch only micro app routes 30 | if (event.url.startsWith(`/${ environment.APP_URL }`)) { 31 | // Uncomment to see tracing 32 | // console.log('[Orders] setLastSuccessfulNavigationUrl', event.url); 33 | this.navigationService.setLastSuccessfulNavigationUrl(event.url); 34 | } 35 | } 36 | }); 37 | } 38 | 39 | public ngDoBootstrap() { 40 | const myElement = createCustomElement(AppComponent, { injector: this.injector }); 41 | customElements.define('app-micro-frontend-orders-root', myElement); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/core/services/navigation.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | @Injectable({ 4 | providedIn: 'root', 5 | }) 6 | export class NavigationService { 7 | private lastSuccessfulNavigationUrl: string; 8 | 9 | public setLastSuccessfulNavigationUrl(url: string): void { 10 | this.lastSuccessfulNavigationUrl = url; 11 | } 12 | 13 | public getLastSuccessfulNavigationUrl() { 14 | return this.lastSuccessfulNavigationUrl; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-info/details-info-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { DetailsInfoComponent } from './details-info.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: DetailsInfoComponent, 9 | }, 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | }) 16 | export class DetailsInfoRoutingModule { 17 | } 18 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-info/details-info.component.html: -------------------------------------------------------------------------------- 1 |

Basic information

2 |
3 |
Phasellus porttitor
4 |
urna vitae massa varius volutpat
5 | 6 |
Curabitur tincidunt purus vitae velit commodo, eu placerat sapien vulputate
7 |
Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo 8 | sit amet risus 9 |
10 | 11 |
Donec hendrerit tellus nec turpis ultricies hendrerit
12 |
13 |
14 |
Nam gravida
15 |
Ut id risus nec quam imperdiet consectetur eget et sem
16 |
17 |
18 |
Molestie aliquam
19 |
Integer accumsan tellus vitae nisi ornare, id feugiat erat ullamcorper.
20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-info/details-info.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/app/details-info/details-info.component.scss -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-info/details-info.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-details-info', 5 | templateUrl: './details-info.component.html', 6 | styleUrls: ['./details-info.component.scss'], 7 | }) 8 | export class DetailsInfoComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-info/details-info.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { DetailsInfoRoutingModule } from './details-info-routing.module'; 5 | import { DetailsInfoComponent } from './details-info.component'; 6 | 7 | @NgModule({ 8 | declarations: [DetailsInfoComponent], 9 | imports: [ 10 | CommonModule, 11 | DetailsInfoRoutingModule, 12 | ], 13 | }) 14 | export class DetailsInfoModule { 15 | } 16 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-shipping/details-shipping-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { DetailsShippingComponent } from './details-shipping.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: DetailsShippingComponent, 9 | }, 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | }) 16 | export class DetailsShippingRoutingModule { 17 | } 18 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-shipping/details-shipping.component.html: -------------------------------------------------------------------------------- 1 |

Shipping

2 | 9 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-shipping/details-shipping.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/app/details-shipping/details-shipping.component.scss -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-shipping/details-shipping.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-details-shipping', 5 | templateUrl: './details-shipping.component.html', 6 | styleUrls: ['./details-shipping.component.scss'], 7 | }) 8 | export class DetailsShippingComponent implements OnInit { 9 | 10 | constructor() { 11 | } 12 | 13 | ngOnInit() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/details-shipping/details-shipping.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { DetailsShippingRoutingModule } from './details-shipping-routing.module'; 5 | import { DetailsShippingComponent } from './details-shipping.component'; 6 | 7 | @NgModule({ 8 | declarations: [DetailsShippingComponent], 9 | imports: [ 10 | CommonModule, 11 | DetailsShippingRoutingModule, 12 | ], 13 | }) 14 | export class DetailsShippingModule { 15 | } 16 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-details/order-details-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { OrderDetailsComponent } from './order-details.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: OrderDetailsComponent, 9 | children: [ 10 | { 11 | path: '', 12 | pathMatch: 'full', 13 | loadChildren: () => import('../details-info/details-info.module').then(m => m.DetailsInfoModule), 14 | }, 15 | { 16 | path: 'shipping', 17 | loadChildren: () => import('../details-shipping/details-shipping.module').then(m => m.DetailsShippingModule), 18 | }, 19 | ], 20 | }, 21 | ]; 22 | 23 | @NgModule({ 24 | imports: [RouterModule.forChild(routes)], 25 | exports: [RouterModule], 26 | }) 27 | export class OrderDetailsRoutingModule { 28 | } 29 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-details/order-details.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 12 |
13 |
14 | 15 |
16 |
17 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-details/order-details.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/app/order-details/order-details.component.scss -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-details/order-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-order-details', 5 | templateUrl: './order-details.component.html', 6 | styleUrls: ['./order-details.component.scss'], 7 | }) 8 | export class OrderDetailsComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-details/order-details.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { OrderDetailsRoutingModule } from './order-details-routing.module'; 5 | import { OrderDetailsComponent } from './order-details.component'; 6 | 7 | @NgModule({ 8 | declarations: [OrderDetailsComponent], 9 | imports: [ 10 | CommonModule, 11 | OrderDetailsRoutingModule, 12 | ], 13 | }) 14 | export class OrderDetailsModule { 15 | } 16 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/models/order-list-element.model.ts: -------------------------------------------------------------------------------- 1 | export interface OrderListElementModel { 2 | date: string; 3 | id: string; 4 | status: string; 5 | amount: string; 6 | } 7 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/order-list-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { OrderListComponent } from './order-list.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: OrderListComponent, 9 | }, 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | }) 16 | export class OrderListRoutingModule { 17 | } 18 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/order-list.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
DateIDStatusAmount
{{order.date}}{{order.id}}1{{order.status}}{{order.amount}}
19 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/order-list.component.scss: -------------------------------------------------------------------------------- 1 | table.clickable-rows tbody tr { 2 | cursor: pointer; 3 | } 4 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/order-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { OrderListElementModel } from './models/order-list-element.model'; 3 | import { OrderListService } from './services/order-list.service'; 4 | 5 | @Component({ 6 | selector: 'app-order-list', 7 | templateUrl: './order-list.component.html', 8 | styleUrls: ['./order-list.component.scss'], 9 | }) 10 | export class OrderListComponent implements OnInit { 11 | 12 | public orders: OrderListElementModel[] = []; 13 | 14 | constructor(private readonly orderListService: OrderListService) { 15 | } 16 | 17 | public ngOnInit() { 18 | this.orderListService.findOrders().subscribe(orders => this.orders = orders); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/order-list.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { OrderListRoutingModule } from './order-list-routing.module'; 5 | import { OrderListComponent } from './order-list.component'; 6 | import { OrderListService } from './services/order-list.service'; 7 | 8 | @NgModule({ 9 | providers: [OrderListService], 10 | declarations: [OrderListComponent], 11 | imports: [ 12 | CommonModule, 13 | OrderListRoutingModule, 14 | ], 15 | }) 16 | export class OrderListModule { 17 | } 18 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/order-list/services/order-list.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Observable, of } from 'rxjs'; 3 | import { OrderListElementModel } from '../models/order-list-element.model'; 4 | 5 | @Injectable() 6 | export class OrderListService { 7 | private orders: OrderListElementModel[] = [ 8 | { 9 | date: '2019-06-16', 10 | id: 'e074dd59-6f6a-441f-858e-b1422d21124d', 11 | status: 'Confirmed', 12 | amount: '28.34', 13 | }, 14 | { 15 | date: '2019-06-15', 16 | id: '20cd22ba-97f0-4650-8d94-dbab7667c37a', 17 | status: 'Confirmed', 18 | amount: '131.99', 19 | }, 20 | { 21 | date: '2019-06-10', 22 | id: 'e08dfb85-daa0-41de-8da3-c3f07f48318a', 23 | status: 'On hold', 24 | amount: '53.00', 25 | }, 26 | { 27 | date: '2019-05-29', 28 | id: '6f53df52-c250-40b6-b11f-2101902cf9fc', 29 | status: 'Closed', 30 | amount: '2.99', 31 | }, 32 | { 33 | date: '2019-05-28', 34 | id: 'fb40d7f8-2d9a-46ac-884b-5e215ca2c985', 35 | status: 'Closed', 36 | amount: '7.99', 37 | }, 38 | ] as OrderListElementModel[]; 39 | 40 | public findOrders(): Observable { 41 | return of(this.orders); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/orders/orders-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { OrdersComponent } from './orders.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: OrdersComponent, 9 | children: [ 10 | { 11 | path: '', 12 | pathMatch: 'full', 13 | loadChildren: () => import('../order-list/order-list.module').then(m => m.OrderListModule), 14 | }, 15 | { 16 | path: ':id', 17 | loadChildren: () => import('../order-details/order-details.module').then(m => m.OrderDetailsModule), 18 | }, 19 | ], 20 | }, 21 | ]; 22 | 23 | @NgModule({ 24 | imports: [RouterModule.forChild(routes)], 25 | exports: [RouterModule], 26 | }) 27 | export class OrdersRoutingModule { 28 | } 29 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/orders/orders.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Orders Application

4 |
5 | 6 |
7 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/orders/orders.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/app/orders/orders.component.scss -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/orders/orders.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-orders', 5 | templateUrl: './orders.component.html', 6 | styleUrls: ['./orders.component.scss'], 7 | }) 8 | export class OrdersComponent { 9 | } 10 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/orders/orders.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { OrdersRoutingModule } from './orders-routing.module'; 5 | import { OrdersComponent } from './orders.component'; 6 | 7 | @NgModule({ 8 | declarations: [OrdersComponent], 9 | imports: [ 10 | CommonModule, 11 | OrdersRoutingModule, 12 | ], 13 | }) 14 | export class OrdersModule { 15 | } 16 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/app/shared/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/app/shared/.gitkeep -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/assets/.gitkeep -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | APP_URL: 'orders', 4 | }; 5 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/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 | APP_URL: 'orders', 8 | }; 9 | 10 | /* 11 | * For easier debugging in development mode, you can import the following file 12 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 13 | * 14 | * This import should be commented out in production mode because it will have a negative impact 15 | * on performance if an error is thrown. 16 | */ 17 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 18 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-app-orders/src/favicon.ico -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MicroFrontendAppOrders 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 18 | 21 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/main.ts: -------------------------------------------------------------------------------- 1 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 2 | import { AppModule } from './app/app.module'; 3 | 4 | // Can't be called again if Envelope app do the same 5 | // 6 | // if (environment.production) { 7 | // enableProdMode(); 8 | // } 9 | 10 | platformBrowserDynamic().bootstrapModule(AppModule) 11 | .catch(err => console.error(err)); 12 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/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 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import { getTestBed } from '@angular/core/testing'; 4 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; 5 | import 'zone.js/dist/zone-testing'; 6 | 7 | declare const require: any; 8 | 9 | // First, initialize the Angular testing environment. 10 | getTestBed().initTestEnvironment( 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting(), 13 | ); 14 | // Then we find all the tests. 15 | const context = require.context('./', true, /\.spec\.ts$/); 16 | // And load the modules. 17 | context.keys().map(context); 18 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "src/test.ts", 12 | "src/**/*.spec.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "esnext", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 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 | -------------------------------------------------------------------------------- /micro-frontend-app-orders/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warn" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-use-before-declare": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": true, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } -------------------------------------------------------------------------------- /micro-frontend-app-orders/webpack.extra.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | output: { 3 | jsonpFunction: 'jsonpFunction' + Math.random().toString(36).slice(2) 4 | }, 5 | "externals": { 6 | "rxjs": "rxjs", 7 | "@angular/core": "ng.core", 8 | "@angular/common": "ng.common", 9 | "@angular/platform-browser": "ng.platformBrowser", 10 | "@angular/elements": "ng.elements", 11 | "@angular/router": "ng.router" 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /micro-frontend-envelope/.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 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /micro-frontend-envelope/.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 | -------------------------------------------------------------------------------- /micro-frontend-envelope/README.md: -------------------------------------------------------------------------------- 1 | Envelope 2 | ============================================================================================== 3 | 4 | Fully functional Angular app acting as a shell for micro apps 5 | 6 | --- 7 | #### Technologies and tools used 8 | 9 | - [Angular](https://angular.io/) with use of [Angular Elements](https://angular.io/guide/elements) 10 | - [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) 11 | - [ngx-build-plus](https://github.com/manfredsteyer/ngx-build-plus) 12 | 13 | Current status: 14 | - :heavy_check_mark: Angular 8 15 | - :heavy_check_mark: Lazy loading 16 | - :heavy_check_mark: External bundles loaded once at startup, lightweight micro apps 17 | - :heavy_check_mark: Angular router fully working (:grey_exclamation: with additional boilerplate in other micro apps) 18 | - :x: Ivy compiler [[not supported yet]](https://github.com/angular/angular/issues/30262#issuecomment-497101996) 19 | 20 | --- 21 | #### Setup / Usage / How to 22 | 23 | ###### Development server 24 | 25 | Run `npm run start` for a dev server. Navigate to `http://localhost:4200/`. 26 | The app will automatically reload if you change any of the source files. 27 | You can also test production setup running `npm run start:prod` 28 | 29 | ###### Build 30 | 31 | Run `npm run bundle` to copy needed assets and build the project. 32 | The build artifacts will be stored in the `dist/` directory. 33 | 34 | ###### Serve production build statics 35 | 36 | Run `npm run server` 37 | 38 | ###### Running unit tests 39 | 40 | Run `npm run test` to execute the unit tests via [Karma](https://karma-runner.github.io). 41 | 42 | ###### Running end-to-end tests 43 | 44 | Run `npm run e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 45 | 46 | --- 47 | #### Areas for improvements 48 | 49 | - Angular routing: some global actions (_back_ and _forward_ action behaviour) 50 | are being caught by all Angular micro-apps currently run in single web page 51 | -------------------------------------------------------------------------------- /micro-frontend-envelope/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "micro-frontend-envelope": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "ngx-build-plus:browser", 19 | "options": { 20 | "outputPath": "dist", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": false, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets" 29 | ], 30 | "styles": [ 31 | "node_modules/bootstrap/dist/css/bootstrap.min.css", 32 | "src/styles.scss" 33 | ], 34 | "scripts": [ 35 | "node_modules/jquery/dist/jquery.slim.min.js", 36 | "node_modules/popper.js/dist/umd/popper.min.js", 37 | "node_modules/bootstrap/dist/js/bootstrap.min.js", 38 | "node_modules/chart.js/dist/Chart.bundle.min.js" 39 | ] 40 | }, 41 | "configurations": { 42 | "production": { 43 | "fileReplacements": [ 44 | { 45 | "replace": "src/environments/environment.ts", 46 | "with": "src/environments/environment.prod.ts" 47 | } 48 | ], 49 | "optimization": true, 50 | "outputHashing": "all", 51 | "sourceMap": false, 52 | "extractCss": true, 53 | "namedChunks": false, 54 | "aot": true, 55 | "extractLicenses": true, 56 | "vendorChunk": false, 57 | "buildOptimizer": true, 58 | "budgets": [ 59 | { 60 | "type": "initial", 61 | "maximumWarning": "2mb", 62 | "maximumError": "5mb" 63 | } 64 | ] 65 | } 66 | } 67 | }, 68 | "serve": { 69 | "builder": "ngx-build-plus:dev-server", 70 | "options": { 71 | "browserTarget": "micro-frontend-envelope:build" 72 | }, 73 | "configurations": { 74 | "production": { 75 | "browserTarget": "micro-frontend-envelope:build:production" 76 | } 77 | } 78 | }, 79 | "extract-i18n": { 80 | "builder": "@angular-devkit/build-angular:extract-i18n", 81 | "options": { 82 | "browserTarget": "micro-frontend-envelope:build" 83 | } 84 | }, 85 | "test": { 86 | "builder": "@angular-devkit/build-angular:karma", 87 | "options": { 88 | "main": "src/test.ts", 89 | "polyfills": "src/polyfills.ts", 90 | "tsConfig": "tsconfig.spec.json", 91 | "karmaConfig": "karma.conf.js", 92 | "assets": [ 93 | "src/favicon.ico", 94 | "src/assets" 95 | ], 96 | "styles": [ 97 | "src/styles.scss" 98 | ], 99 | "scripts": [] 100 | } 101 | }, 102 | "lint": { 103 | "builder": "@angular-devkit/build-angular:tslint", 104 | "options": { 105 | "tsConfig": [ 106 | "tsconfig.app.json", 107 | "tsconfig.spec.json", 108 | "e2e/tsconfig.json" 109 | ], 110 | "exclude": [ 111 | "**/node_modules/**" 112 | ] 113 | } 114 | }, 115 | "e2e": { 116 | "builder": "@angular-devkit/build-angular:protractor", 117 | "options": { 118 | "protractorConfig": "e2e/protractor.conf.js", 119 | "devServerTarget": "micro-frontend-envelope:serve" 120 | }, 121 | "configurations": { 122 | "production": { 123 | "devServerTarget": "micro-frontend-envelope:serve:production" 124 | } 125 | } 126 | } 127 | } 128 | } 129 | }, 130 | "defaultProject": "micro-frontend-envelope" 131 | } 132 | -------------------------------------------------------------------------------- /micro-frontend-envelope/browserslist: -------------------------------------------------------------------------------- 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 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /micro-frontend-envelope/copy-bundles.js: -------------------------------------------------------------------------------- 1 | // This script copies over UMD bundles to the project's assets folder 2 | 3 | const copy = require('copy'); 4 | 5 | console.log('Copy UMD bundles ...'); 6 | 7 | copy('node_modules/@angular/*/bundles/*.umd.js', 'src/assets', {}, _ => {}); 8 | copy('node_modules/rxjs/bundles/*.js', 'src/assets/rxjs', {}, _ => {}); 9 | copy('node_modules/zone.js/dist/*.js', 'src/assets/zone.js', {}, _ => {}); 10 | -------------------------------------------------------------------------------- /micro-frontend-envelope/copy-wc-polyfills.js: -------------------------------------------------------------------------------- 1 | // This script copies over some polyfills to the project's assets folder 2 | const copy = require('copy'); 3 | 4 | console.log('Copy webcomponent polyfills ...'); 5 | 6 | copy('node_modules/@webcomponents/**/*.js', 'src/assets', {}, _ => {}); 7 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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 } = 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 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /micro-frontend-envelope/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 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', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to micro-frontend-envelope!'); 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 | -------------------------------------------------------------------------------- /micro-frontend-envelope/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /micro-frontend-envelope/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/micro-frontend-envelope'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /micro-frontend-envelope/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "micro-frontend-envelope", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --extraWebpackConfig webpack.extra.js", 7 | "start:prod": "ng serve --aot --prod=true --vendor-chunk=false --optimization=true --extraWebpackConfig webpack.extra.js", 8 | "build": "ng build --prod --extraWebpackConfig webpack.bundle.extra.js", 9 | "build:aws": "ng build --prod --extraWebpackConfig webpack.bundle.aws.extra.js", 10 | "copy-bundles": "node copy-bundles.js", 11 | "copy-wc-polyfills": "node copy-wc-polyfills.js", 12 | "bundle": "npm run copy-bundles && npm run copy-wc-polyfills && npm run build", 13 | "bundle:aws": "npm run copy-bundles && npm run copy-wc-polyfills && npm run build:aws", 14 | "server": "http-server dist -p 8200", 15 | "test": "ng test", 16 | "lint": "ng lint", 17 | "e2e": "ng e2e" 18 | }, 19 | "private": true, 20 | "dependencies": { 21 | "@angular/animations": "~8.0.0", 22 | "@angular/common": "~8.0.0", 23 | "@angular/compiler": "~8.0.0", 24 | "@angular/core": "~8.0.0", 25 | "@angular/elements": "~8.0.0", 26 | "@angular/forms": "~8.0.0", 27 | "@angular/platform-browser": "~8.0.0", 28 | "@angular/platform-browser-dynamic": "~8.0.0", 29 | "@angular/router": "~8.0.0", 30 | "@webcomponents/custom-elements": "^1.2.4", 31 | "bootstrap": "^4.3.1", 32 | "chart.js": "^2.8.0", 33 | "core-js": "^3.1.4", 34 | "jquery": "^3.4.1", 35 | "ng2-charts": "^2.3.0", 36 | "popper.js": "^1.15.0", 37 | "rxjs": "~6.4.0", 38 | "tslib": "^1.9.0", 39 | "zone.js": "~0.9.1" 40 | }, 41 | "devDependencies": { 42 | "@angular-devkit/build-angular": "~0.800.0", 43 | "@angular/cli": "~8.0.2", 44 | "@angular/compiler-cli": "~8.0.0", 45 | "@angular/language-service": "~8.0.0", 46 | "@types/jasmine": "~3.3.8", 47 | "@types/jasminewd2": "~2.0.3", 48 | "@types/node": "~8.9.4", 49 | "codelyzer": "^5.0.0", 50 | "copy": "^0.3.2", 51 | "http-server": "^0.11.1", 52 | "jasmine-core": "~3.4.0", 53 | "jasmine-spec-reporter": "~4.2.1", 54 | "karma": "~4.1.0", 55 | "karma-chrome-launcher": "~2.2.0", 56 | "karma-coverage-istanbul-reporter": "~2.0.1", 57 | "karma-jasmine": "~2.0.1", 58 | "karma-jasmine-html-reporter": "^1.4.0", 59 | "ngx-build-plus": "^8.0.3", 60 | "protractor": "~5.4.0", 61 | "ts-node": "~7.0.0", 62 | "tslint": "~5.15.0", 63 | "typescript": "~3.4.3" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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: '', 7 | loadChildren: () => import('./envelope/envelope.module').then(m => m.EnvelopeModule), 8 | }, 9 | ]; 10 | 11 | @NgModule({ 12 | imports: [RouterModule.forRoot(routes, { useHash: true })], 13 | exports: [RouterModule], 14 | }) 15 | export class AppRoutingModule { 16 | } 17 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-envelope/src/app/app.component.scss -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, 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 | 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.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'micro-frontend-envelope'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('micro-frontend-envelope'); 27 | }); 28 | 29 | it('should render title in a h1 tag', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to micro-frontend-envelope!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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.scss'], 7 | }) 8 | export class AppComponent { 9 | } 10 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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: [AppComponent], 9 | imports: [ 10 | BrowserModule, 11 | AppRoutingModule, 12 | ], 13 | providers: [], 14 | bootstrap: [AppComponent], 15 | }) 16 | export class AppModule { 17 | } 18 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/core/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-envelope/src/app/core/.gitkeep -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/dashboard/dashboard-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { DashboardComponent } from './dashboard.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | component: DashboardComponent, 9 | }, 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [RouterModule.forChild(routes)], 14 | exports: [RouterModule], 15 | }) 16 | export class DashboardRoutingModule { 17 | } 18 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/dashboard/dashboard.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Envelope Dashboard

4 |
5 |
6 | 11 | 12 |
13 |
14 | 18 | 19 |
20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/dashboard/dashboard.component.scss: -------------------------------------------------------------------------------- 1 | .dashboard-section { 2 | h2 { 3 | text-align: center; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/dashboard/dashboard.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { ChartDataSets, ChartType, RadialChartOptions } from 'chart.js'; 3 | import { Label, MultiDataSet } from 'ng2-charts'; 4 | 5 | @Component({ 6 | selector: 'app-envelope-dashboard', 7 | templateUrl: './dashboard.component.html', 8 | styleUrls: ['./dashboard.component.scss'], 9 | }) 10 | export class DashboardComponent { 11 | // Radar 12 | public radarChartOptions: RadialChartOptions = { 13 | responsive: true, 14 | }; 15 | public radarChartLabels: Label[] = ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running']; 16 | 17 | public radarChartData: ChartDataSets[] = [ 18 | { data: [65, 59, 90, 81, 56, 55, 40], label: 'Series A' }, 19 | { data: [28, 48, 40, 19, 96, 27, 100], label: 'Series B' }, 20 | ]; 21 | public radarChartType: ChartType = 'radar'; 22 | 23 | // Doughnut 24 | public doughnutChartLabels: Label[] = ['Download Sales', 'In-Store Sales', 'Mail-Order Sales']; 25 | public doughnutChartData: MultiDataSet = [ 26 | [350, 450, 100], 27 | [50, 150, 120], 28 | [250, 130, 70], 29 | ]; 30 | public doughnutChartType: ChartType = 'doughnut'; 31 | } 32 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/dashboard/dashboard.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | import { ChartsModule } from 'ng2-charts'; 4 | 5 | import { DashboardRoutingModule } from './dashboard-routing.module'; 6 | import { DashboardComponent } from './dashboard.component'; 7 | 8 | @NgModule({ 9 | declarations: [DashboardComponent], 10 | imports: [ 11 | CommonModule, 12 | DashboardRoutingModule, 13 | // Just for charts, not required 14 | ChartsModule, 15 | ], 16 | }) 17 | export class DashboardModule { 18 | } 19 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/component/micro-app/micro-app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | // Provided at build time, depends if you load micro apps 4 | // from relative context or directly from other domain / port 5 | declare const SOURCES_URL_PREFIX: string; 6 | 7 | @Component({ 8 | selector: 'app-envelope-micro-app', 9 | template: `
There should render micro-app!
`, 10 | }) 11 | export class MicroAppComponent implements OnInit { 12 | private readonly CUSTOM_ELEMENT_CONTAINER_ID = 'micro-app-web-component'; 13 | 14 | private appSelector = 'app-micro-frontend-orders-root'; 15 | private appUrlPrefix = `${ SOURCES_URL_PREFIX }/micro-frontend-app-orders`; 16 | 17 | public ngOnInit() { 18 | const content = document.getElementById(this.CUSTOM_ELEMENT_CONTAINER_ID); 19 | if (!this.isRegistered(this.appSelector)) { 20 | // tslint:disable-next-line:no-console 21 | console.debug(`Loading Web Component ${ this.appSelector } from ${ this.appUrlPrefix }`); 22 | this.loadScripts(content, this.appUrlPrefix); 23 | } else { 24 | // tslint:disable-next-line:no-console 25 | console.debug(`Web Component ${ this.appSelector } already loaded!`); 26 | } 27 | 28 | const element: HTMLElement = document.createElement(this.appSelector); 29 | content.innerHTML = ''; 30 | content.appendChild(element); 31 | } 32 | 33 | private loadScripts(containerElement: HTMLElement, url: string) { 34 | for (const standard of ['es5', 'es2015']) { 35 | const script = document.createElement('script'); 36 | script.src = `${ url }/main-${ standard }.js`; 37 | if ('es5' === standard) { 38 | script.noModule = true; 39 | } else if ('es2015' === standard) { 40 | script.type = 'module'; 41 | } 42 | containerElement.appendChild(script); 43 | script.onerror = () => { 44 | throw new Error(`Error occurred when loading ${ url }`); 45 | }; 46 | } 47 | } 48 | 49 | private isRegistered(name) { 50 | return document.createElement(name).constructor !== HTMLElement; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/component/nav/nav.component.html: -------------------------------------------------------------------------------- 1 | 30 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/component/nav/nav.component.scss: -------------------------------------------------------------------------------- 1 | nav.navbar { 2 | input[type="search"] { 3 | width: 400px; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/component/nav/nav.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-envelope-nav', 5 | templateUrl: './nav.component.html', 6 | styleUrls: ['nav.component.scss'], 7 | }) 8 | export class NavComponent { 9 | } 10 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/envelope-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { MicroAppComponent } from './component/micro-app/micro-app.component'; 4 | import { EnvelopeComponent } from './envelope.component'; 5 | 6 | const routes: Routes = [{ 7 | path: '', 8 | component: EnvelopeComponent, 9 | children: [ 10 | { 11 | path: '', 12 | pathMatch: 'full', 13 | redirectTo: 'dashboard', 14 | }, 15 | { 16 | path: 'dashboard', 17 | loadChildren: () => import('../dashboard/dashboard.module').then(m => m.DashboardModule), 18 | }, 19 | { 20 | path: ':microAppName', 21 | children: [ 22 | { 23 | path: '**', 24 | component: MicroAppComponent, 25 | }, 26 | ], 27 | }, 28 | ], 29 | }]; 30 | 31 | @NgModule({ 32 | imports: [RouterModule.forChild(routes)], 33 | exports: [RouterModule], 34 | }) 35 | export class EnvelopeRoutingModule { 36 | } 37 | 38 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/envelope.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/envelope.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-envelope', 5 | templateUrl: './envelope.component.html', 6 | }) 7 | export class EnvelopeComponent { 8 | } 9 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/envelope/envelope.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | import { MicroAppComponent } from './component/micro-app/micro-app.component'; 4 | import { NavComponent } from './component/nav/nav.component'; 5 | 6 | import { EnvelopeRoutingModule } from './envelope-routing.module'; 7 | import { EnvelopeComponent } from './envelope.component'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | NavComponent, 12 | MicroAppComponent, 13 | EnvelopeComponent, 14 | ], 15 | imports: [ 16 | CommonModule, 17 | EnvelopeRoutingModule, 18 | ], 19 | }) 20 | export class EnvelopeModule { 21 | } 22 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/app/shared/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-envelope/src/app/shared/.gitkeep -------------------------------------------------------------------------------- /micro-frontend-envelope/src/assets/.gitignore: -------------------------------------------------------------------------------- 1 | # @webcomponent 2 | /custom-elements 3 | 4 | # @angular 5 | /animations 6 | /common 7 | /compiler 8 | /core 9 | /elements 10 | /forms 11 | /language-service 12 | /platform-browser 13 | /platform-browser-dynamic 14 | /router 15 | 16 | /rxjs 17 | /zone.js 18 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | }; 4 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/micro-frontend-envelope/src/favicon.ico -------------------------------------------------------------------------------- /micro-frontend-envelope/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MicroFrontendEnvelope 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/main.ts: -------------------------------------------------------------------------------- 1 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 2 | 3 | import { AppModule } from './app/app.module'; 4 | 5 | // Can't be called again if already done when loading core scripts 6 | // @see: index.html 7 | // 8 | // if (environment.production) { 9 | // enableProdMode(); 10 | // } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | -------------------------------------------------------------------------------- /micro-frontend-envelope/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 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /micro-frontend-envelope/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import { getTestBed } from '@angular/core/testing'; 4 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; 5 | import 'zone.js/dist/zone-testing'; 6 | 7 | declare const require: any; 8 | 9 | // First, initialize the Angular testing environment. 10 | getTestBed().initTestEnvironment( 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting(), 13 | ); 14 | // Then we find all the tests. 15 | const context = require.context('./', true, /\.spec\.ts$/); 16 | // And load the modules. 17 | context.keys().map(context); 18 | -------------------------------------------------------------------------------- /micro-frontend-envelope/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "src/test.ts", 12 | "src/**/*.spec.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /micro-frontend-envelope/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "esnext", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /micro-frontend-envelope/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 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 | -------------------------------------------------------------------------------- /micro-frontend-envelope/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warn" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-use-before-declare": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": true, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } -------------------------------------------------------------------------------- /micro-frontend-envelope/webpack.bundle.aws.extra.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | new webpack.DefinePlugin({ 6 | 'SOURCES_URL_PREFIX': JSON.stringify('.') 7 | }) 8 | ], 9 | output: { 10 | jsonpFunction: 'jsonpFunction' + Math.random().toString(36).slice(2) 11 | }, 12 | 'externals': { 13 | 'rxjs': 'rxjs', 14 | '@angular/core': 'ng.core', 15 | '@angular/common': 'ng.common', 16 | '@angular/platform-browser': 'ng.platformBrowser', 17 | '@angular/elements': 'ng.elements', 18 | '@angular/router': 'ng.router' 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /micro-frontend-envelope/webpack.bundle.extra.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | new webpack.DefinePlugin({ 6 | 'SOURCES_URL_PREFIX': JSON.stringify('http://localhost:8201') 7 | }) 8 | ], 9 | output: { 10 | jsonpFunction: 'jsonpFunction' + Math.random().toString(36).slice(2) 11 | }, 12 | 'externals': { 13 | 'rxjs': 'rxjs', 14 | '@angular/core': 'ng.core', 15 | '@angular/common': 'ng.common', 16 | '@angular/platform-browser': 'ng.platformBrowser', 17 | '@angular/elements': 'ng.elements', 18 | '@angular/router': 'ng.router' 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /micro-frontend-envelope/webpack.extra.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | new webpack.DefinePlugin({ 6 | 'SOURCES_URL_PREFIX': JSON.stringify('http://localhost:8201') 7 | }) 8 | ], 9 | output: { 10 | jsonpFunction: 'jsonpFunction' + Math.random().toString(36).slice(2) 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /prepare-sources-s3.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | npm run --prefix micro-frontend-envelope bundle:aws 3 | npm run --prefix micro-frontend-app-orders build:aws 4 | rm -rf ./static/ 5 | cp -R micro-frontend-envelope/dist/ ./static/ 6 | cp -R micro-frontend-app-orders/dist/micro-frontend-app-orders ./static/ 7 | aws s3 rm s3://$1 --recursive 8 | aws s3 sync ./static/ s3://$1/ 9 | -------------------------------------------------------------------------------- /showcase.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmagrys/micro-frontend-architecture/97e5f84575040da2fd3331218194b0caf4cf9f5e/showcase.gif --------------------------------------------------------------------------------