{"id":13393662,"url":"https://github.com/phodal/mooa","last_synced_at":"2025-05-16T09:04:33.742Z","repository":{"id":41070605,"uuid":"124352426","full_name":"phodal/mooa","owner":"phodal","description":"Mooa 是一个为 Angular 服务的微前端框架。A independent-deployment micro-frontend Framework for Angular from single-spa.","archived":false,"fork":false,"pushed_at":"2020-05-28T14:12:54.000Z","size":2614,"stargazers_count":854,"open_issues_count":0,"forks_count":109,"subscribers_count":39,"default_branch":"master","last_synced_at":"2025-05-02T04:16:24.584Z","etag":null,"topics":["angular","micro-frontend","microframework","microfrontends","microservices","microservices-architecture","spa"],"latest_commit_sha":null,"homepage":"http://mooa.phodal.com/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phodal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"phodal","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"custom":null}},"created_at":"2018-03-08T07:15:27.000Z","updated_at":"2025-03-27T17:48:55.000Z","dependencies_parsed_at":"2022-08-03T12:20:38.442Z","dependency_job_id":null,"html_url":"https://github.com/phodal/mooa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phodal%2Fmooa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phodal%2Fmooa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phodal%2Fmooa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phodal%2Fmooa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phodal","download_url":"https://codeload.github.com/phodal/mooa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501556,"owners_count":22081528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","micro-frontend","microframework","microfrontends","microservices","microservices-architecture","spa"],"created_at":"2024-07-30T17:00:58.256Z","updated_at":"2025-05-16T09:04:30.969Z","avatar_url":"https://github.com/phodal.png","language":"TypeScript","readme":"# Mooa\n\n[![Build Status](https://travis-ci.org/phodal/mooa.svg?branch=master)](https://travis-ci.org/phodal/mooa)\n[![Coverage Status](https://coveralls.io/repos/github/phodal/mooa/badge.svg?branch=master)](https://coveralls.io/github/phodal/mooa?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/99132c580e1d74690def/maintainability)](https://codeclimate.com/github/phodal/mooa/maintainability)\n[![node](https://img.shields.io/node/v/mooa.svg)](https://www.npmjs.com/package/mooa) \n[![npm](https://img.shields.io/npm/v/mooa.svg)](https://www.npmjs.com/mooa)\n\n\u003e A single SPA Utils for Angular 2+\n\nSimliar Projects: [https://github.com/worktile/ngx-planet](https://github.com/worktile/ngx-planet) (Production Ready)\n\nbased on [single-spa](https://github.com/CanopyTax/single-spa) \u0026\u0026 [single-spa-angular-cli](https://github.com/PlaceMe-SAS/single-spa-angular-cli)\n\ndifference: \n\n - Host \u003c-\u003e Apps Architecture\n - Configurable App (no loader require)\n - Independent App in Different Repo and runnable\n\n![Mooa Architecture](docs/mooa.png)\n\nExamples: see in [examples/](examples)\n\nOnline Demo: \n\n1. [http://mooa.pho.im/](http://mooa.pho.im/) (host in AWS S3)\n2. [http://mooa.phodal.com/](http://mooa.phodal.com/) (host in GitHub Pages)\n\nFeatures:\n\n1. SPA by Configurable file, ex: ``apps.json``\n2. Pluggable APP\n3. support Child APP navigate\n4. CLI for Generate Config\n\nGoal:\n\n1. 构建插件化的 Web 开发平台，满足业务快速变化及分布式多团队并行开发的需求\n2. 构建服务化的中间件，搭建高可用及高复用的前端微服务平台\n3. 支持前端的独立交付及部署\n\nUsecase\n---\n\n\u003e If you are mooa, please provide you case to help this project.\n\n### Theory\n\n[Research and Application of Micro Frontends](https://iopscience.iop.org/article/10.1088/1757-899X/490/6/062082/meta)\n\nBoilerplate\n---\n\nApp Boilerplate: [https://github.com/phodal/mooa-boilerplate](https://github.com/phodal/mooa-boilerplate)\n\nUsage\n---\n\n### 1. Install mooa\n\nin Host and Child App\n\n```sh\nyarn add mooa\n```\n\n### 2. Config Host\n\n1. add get Apps logic in AppComponent (``app.component.ts``)\n\n```typescript\nconstructor(private renderer: Renderer2, http: HttpClient, private router: Router) {\n  // config Mooa\n  this.mooa = new Mooa({\n    mode: 'iframe',\n    debug: false,\n    parentElement: 'app-home',\n    urlPrefix: 'app',\n    switchMode: 'coexist',\n    preload: true,\n    includeZone: true\n  });\n  http.get\u003cIAppOption[]\u003e('/assets/apps.json')\n    .subscribe(\n      data =\u003e {\n        this.createApps(data);\n      },\n      err =\u003e console.log(err)\n    );\n}\n\nprivate createApps(data: IAppOption[]) {\n  data.map((config) =\u003e {\n    this.mooa.registerApplication(config.name, config, mooaRouter.matchRoute(config.prefix));\n  });\n\n  this.router.events.subscribe((event) =\u003e {\n    if (event instanceof NavigationEnd) {\n      this.mooa.reRouter(event);\n    }\n  });\n\n  return this.mooa.start();\n}\n```\n\n### 3. Config App\n\n1. config App ``main.ts`` for load\n\n```typescript\nimport { mooaPlatform } from 'mooa';\n\nif (environment.production) {\n  enableProdMode();\n}\n\nmooaPlatform.mount('help').then((opts) =\u003e {\n  platformBrowserDynamic().bootstrapModule(AppModule).then((module) =\u003e {\n    opts['attachUnmount'](module);\n  });\n});\n\n```\n\n2. setup app routing in ``app.module.ts``\n\n```typescript\nconst appRoutes: Routes = [\n  {path: '*', component: AppComponent}\n  ...\n];\n\n@NgModule({\n  declarations: [\n    AppComponent,\n    ...\n  ],\n  imports: [\n    BrowserModule,\n    RouterModule.forRoot(\n      appRoutes\n    )\n  ],\n  providers: [\n    {provide: APP_BASE_HREF, useValue: mooaPlatform.appBase()},\n  ],\n  bootstrap: [AppComponent]\n})\nexport class AppModule {\n\n}\n```\n\n3. Add for handle URL Change in ``app.component.ts`` \n\n```typescript\nconstructor(private router: Router) {\n  mooaPlatform.handleRouterUpdate(this.router, 'app1');\n}\n```\n\n### 4. Setup apps.json with Mooa CLI\n\n1. install global cli\n\n```bash\nnpm install -g mooa\n```\n\n2. create URL list files\n\nExamples: ``apps.txt``\n \n```\nhttp://mooa.phodal.com/assets/app1\nhttp://mooa.phodal.com/assets/help\n```\n\n3. Generate Config File\n\n```bash\nmooa -g apps.txt\n```\n\nExamples:\n\n```json\n[\n  {\n    \"name\": \"app1\",\n    \"selector\": \"app-app1\",\n    \"baseScriptUrl\": \"/assets/app1\",\n    \"styles\": [\n      \"styles.bundle.css\"\n    ],\n    \"prefix\": \"app/app1\",\n    \"scripts\": [\n      \"inline.bundle.js\",\n      \"polyfills.bundle.js\",\n      \"main.bundle.js\"\n    ]\n  }\n]\n```\n\nMooa Config\n---\n\nconfig in Host app's ``app.component.ts`` \n\n```typescript\nthis.mooa = new Mooa({\n  mode: 'iframe',\n  debug: false,\n  parentElement: 'app-home',\n  urlPrefix: 'app',\n  switchMode: 'coexist'\n}) \n```\n\n### mode: 'iframe'\n\nuse iframe as application container:\n\n```html\n\u003capp-home _nghost-c2=\"\"\u003e\n  \u003ciframe frameborder=\"\" width=\"100%\" height=\"100%\" src=\"http://localhost:4200/app/help/homeassets/iframe.html\" id=\"help_206547\"\u003e\u003c/iframe\u003e\n\u003c/app-home\u003e\n```\n\n### switchMode: 'coexist'\n\nhidden application when inactive:\n\n```html\n\u003capp-home _nghost-c2=\"\"\u003e\n  \u003capp-app1 _nghost-c0=\"\" ng-version=\"5.2.8\" style=\"display: none;\"\u003e\u003cnav _ngcontent-c0=\"\" class=\"navbar\"\u003e\u003c/app-app1\u003e\n  \u003ciframe frameborder=\"\" width=\"100%\" height=\"100%\" src=\"http://localhost:4200/app/help/homeassets/iframe.html\" id=\"help_206547\"\u003e\u003c/iframe\u003e\n\u003c/app-home\u003e\n```\n\nFor Angular Lazyload Module\n---\n\n``inline.bundle.js`` will load script for ``/`` path. \n\nSo, just copy ``*.chunk.js`` files to ``dist/``, then deploy it.\n\n\nAPI\n---\n\n### registerApplicationByLink\n\nexmples:\n\n```typescript\nmooa.registerApplicationByLink('help', '/assets/help', mooaRouter.matchRoute('help'));\n```\n\n### registerApplication\n\n```typescript\nmooa.registerApplication(config.name, config, mooaRouter.matchRoute(config.prefix));\n```\n\nhybrid\n\n```typescript\nif (config.sourceType) {\n  that.mooa.registerApplicationByLink(config.name, config.link, mooaRouter.matchRoute(config.name));\n} else {\n  that.mooa.registerApplication(config.name, config, mooaRouter.matchRoute(config.prefix));\n}\n```\n\n### navigateTo Custom App\n\n```typescript\nmooaPlatform.navigateTo({\n  appName: 'help',\n  router: 'home'\n});\n```\n\nLicense\n---\n\n[![Phodal's Idea](http://brand.phodal.com/shields/idea-small.svg)](http://ideas.phodal.com/)\n\nCopyright (c) 2013-2014 Christopher Simpkins\nCopyright (c) 2017-2018 Robin Coma Delperier\n\n© 2018 A [Phodal Huang](https://www.phodal.com)'s [Idea](http://github.com/phodal/ideas).  This code is distributed under the MIT license. See `LICENSE` in this directory.\n","funding_links":["https://patreon.com/phodal"],"categories":["Tools","Uncategorized","TypeScript"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphodal%2Fmooa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphodal%2Fmooa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphodal%2Fmooa/lists"}