All Projects → worktile → Ngx Planet

worktile / Ngx Planet

Licence: mit
🚀🌍🚀A powerful, reliable, fully-featured and production ready Micro Frontend library for Angular.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Ngx Planet

react-stick
React component to stick a portaled node to an anchor node
Stars: ✭ 51 (-85.87%)
Mutual labels:  portal
developer-portal
VA Lighthouse (aka VA API Platform) website and documentation.
Stars: ✭ 25 (-93.07%)
Mutual labels:  portal
squest
Service request portal on top of Ansible Tower/AWX
Stars: ✭ 115 (-68.14%)
Mutual labels:  portal
react-append-to-body
React Higher order component that allows you to attach components to the DOM outside of the main app.
Stars: ✭ 30 (-91.69%)
Mutual labels:  portal
hcp-portal-service-samples
Code samples of site and page templates, applications, widgets, shell plugins and more, intended to be used as references for development of custom content for SAP HANA Cloud Platform portal service sites.
Stars: ✭ 29 (-91.97%)
Mutual labels:  portal
opensource-management-portal
Microsoft's monolithic GitHub Management Portal enabling enterprise scale self-service powered by the GitHub API 🏔🧑‍💻🧰
Stars: ✭ 369 (+2.22%)
Mutual labels:  portal
trident
Trident is a trusted and secure communication platform for enabling better communication between groups of trusted parties
Stars: ✭ 21 (-94.18%)
Mutual labels:  portal
Opensource Portal
Microsoft's monolithic GitHub Management Portal enabling enterprise scale self-service powered by the GitHub API 🏔🧑‍💻🧰
Stars: ✭ 273 (-24.38%)
Mutual labels:  portal
portal-demos
A few demos on how the new portal API can be used with React.
Stars: ✭ 14 (-96.12%)
Mutual labels:  portal
safenetwork-gitportal
p2p git portal - a decentralised alternative to github
Stars: ✭ 12 (-96.68%)
Mutual labels:  portal
CoursesPortlet
No description or website provided.
Stars: ✭ 12 (-96.68%)
Mutual labels:  portal
groupepsa.github.io
Documentation for Application Developpers
Stars: ✭ 14 (-96.12%)
Mutual labels:  portal
configurable-app-examples-4x-js
Configurable Application Examples using ApplicationBase
Stars: ✭ 22 (-93.91%)
Mutual labels:  portal
WebproxyPortlet
No description or website provided.
Stars: ✭ 14 (-96.12%)
Mutual labels:  portal
gorails
gorails website
Stars: ✭ 34 (-90.58%)
Mutual labels:  portal
bolsa
Biblioteca feita em Python com o objetivo de facilitar o acesso a dados de seus investimentos na bolsa de valores(B3/CEI) através do Portal CEI.
Stars: ✭ 46 (-87.26%)
Mutual labels:  portal
SourceAutoRecord
Speedrun plugin for Source Engine games.
Stars: ✭ 47 (-86.98%)
Mutual labels:  portal
Portal Vue
A feature-rich Portal Plugin for Vue 2, for rendering DOM outside of a component, anywhere in your app or the entire document.
Stars: ✭ 3,490 (+866.76%)
Mutual labels:  portal
Kupiki Hotspot Script
Create automatically a full Wifi Hotspot on Raspberry Pi including a Captive Portal
Stars: ✭ 265 (-26.59%)
Mutual labels:  portal
react-portal-hoc
A stupid HOC to make a stupid portal so you can make stupid modals
Stars: ✭ 14 (-96.12%)
Mutual labels:  portal

ngx-planet

CircleCI Coverage Status npm (scoped) npm npm bundle size (scoped) All Contributors

A powerful, reliable, fully-featured and production ready Micro Frontend library for Angular.

APIs consistent with angular style, currently only supports Angular, other frameworks are not supported.

中文文档

Features

  • Rendering multiple applications at the same time
  • Support two mode, coexist and default that switch to another app and destroy active apps
  • Support application preload
  • Support style isolation
  • Built-in communication between multiple applications
  • Cross application component rendering
  • Comprehensive examples include routing configuration, lazy loading and all features

Alternatives

  • single-spa: A javascript front-end framework supports any frameworks.
  • mooa: A independent-deployment micro-frontend Framework for Angular from single-spa, planet is very similar to it, but planet is more powerful, reliable, productively and more angular.

Installation

$ npm i @worktile/planet --save
// or
$ yarn add @worktile/planet

Dependencies

  • @angular/cdk, you should install @angular/cdk

Demo

Try out our live demo

ngx-planet-micro-front-end.gif

Usage

1. Loading NgxPlanetModule in the portal's AppModule

import { NgxPlanetModule } from '@worktile/planet';

@NgModule({
  imports: [
    CommonModule,
    NgxPlanetModule
  ]
})
class AppModule {}

2. Register applications to planet use PlanetService in portal app

@Component({
    selector: 'app-portal-root',
    template: `
<nav>
    <a [routerLink]="['/app1']" routerLinkActive="active">应用1</a>
    <a [routerLink]="['/app2']" routerLinkActive="active">应用2</a>
</nav>
<router-outlet></router-outlet>
<div id="app-host-container"></div>
<div *ngIf="!loadingDone">加载中...</div>
    `
})
export class AppComponent implements OnInit {
    title = 'ngx-planet';

    get loadingDone() {
        return this.planet.loadingDone;
    }

    constructor(
        private planet: Planet
    ) {}

    ngOnInit() {
        this.planet.setOptions({
            switchMode: SwitchModes.coexist,
            errorHandler: error => {
                console.error(`Failed to load resource, error:`, error);
            }
        });

        this.planet.registerApps([
            {
                name: 'app1',
                hostParent: '#app-host-container',
                hostClass: 'thy-layout',
                routerPathPrefix: '/app1',
                resourcePathPrefix: '/static/app1',
                preload: true,
                scripts: [
                    'main.js'
                ],
                styles: [
                    'styles.css'
                ]
            },
            {
                name: 'app2',
                hostParent: '#app-host-container',
                hostClass: 'thy-layout',
                routerPathPrefix: '/app2',
                preload: true,
                scripts: [
                    '/static/app2/main.js'
                ],
                styles: [
                    '/static/app2/styles.css'
                ]
            }
        ]);

        // start monitor route changes
        // get apps to active by current path
        // load static resources which contains javascript and css
        // bootstrap angular sub app module and show it
        this.planet.start();
    }
}

3. Sub App define how to bootstrap AppModule

defineApplication('app1', {
    template: `<app1-root class="app1-root"></app1-root>`,
    bootstrap: (portalApp: PlanetPortalApplication) => {
        return platformBrowserDynamic([
            {
                provide: PlanetPortalApplication,
                useValue: portalApp
            },
            {
                provide: AppRootContext,
                useValue: portalApp.data.appRootContext
            }
        ])
            .bootstrapModule(AppModule)
            .then(appModule => {
                return appModule;
            })
            .catch(error => {
                console.error(error);
                return null;
            });
    }
});

Documents

Sub app configurations

Name Type Description 中文描述
name string Application's name 子应用的名字
routerPathPrefix string Application route path prefix 子应用路由路径前缀,根据这个匹配应用
selector string selector of app root component 子应用的启动组件选择器,因为子应用是主应用动态加载的,所以主应用需要先创建这个选择器节点,再启动 AppModule
scripts string[] javascript static resource paths JS 静态资源文件访问地址
styles string[] style static resource paths 样式静态资源文件访问地址
resourcePathPrefix string path prefix of scripts and styles 脚本和样式文件路径前缀,多个脚本可以避免重复写同样的前缀
hostParent string or HTMLElement parent element for render 应用渲染的容器元素, 指定子应用显示在哪个元素内部
hostClass string added class for host which is selector 宿主元素的 Class,也就是在子应用启动组件上追加的样式
switchMode default or coexist it will be destroyed when set to default, it only hide app when set to coexist 切换子应用的模式,默认切换会销毁,设置 coexist 后只会隐藏
preload boolean start preload or not 是否启用预加载,启动后刷新页面等当前页面的应用渲染完毕后预加载子应用
loadSerial boolean serial load scripts 是否串行加载脚本静态资源
manifest string manifest json file path manifest.json 文件路径地址,当设置了路径后会先加载这个文件,然后根据 scripts 和 styles 文件名去找到匹配的文件,因为生产环境的静态资文件是 hash 之后的命名,需要动态获取

Communication between applications use GlobalEventDispatcher

import { GlobalEventDispatcher } from "@worktile/planet";

// app1 root module
export class AppModule {
    constructor(private globalEventDispatcher: GlobalEventDispatcher) {
        this.globalEventDispatcher.register('open-a-detail').subscribe(event => {
            // dialog.open(App1DetailComponent);
        });
    }
}

// in other apps
export class OneComponent {
    constructor(private globalEventDispatcher: GlobalEventDispatcher) {
    }

    openDetail() {
        this.globalEventDispatcher.dispatch('open-a-detail', payload);
    }
}

Cross application component rendering

import { PlanetComponentLoader } from "@worktile/planet";

// in app1
export class AppModule {
    constructor(private planetComponentLoader: PlanetComponentLoader) {
        this.planetComponentLoader.register([{ name: 'app1-project-list', component: App1ProjectListComponent }]);
    }
}

// in other apps
export class OneComponent {
    constructor(private planetComponentLoader: PlanetComponentLoader) {
    }

    openDetail() {
        this.planetComponentLoader.load('app1', 'app1-project-list', {
            container: this.containerElementRef,
            initialState: {}
        });
    }
}

FAQ

infinite loop load portal app's js

Because the portal app and sub app are packaged through webpack, there will be conflicts in module dependent files, we should set up additional config runtimeChunk through @angular-builders/custom-webpack, we expect webpack 5 to support micro frontend better.

// extra-webpack.config.js
{    
    optimization: {
        runtimeChunk: false
    }
};

throw error Cannot read property 'call' of undefined at __webpack_require__ (bootstrap:79)

Similar to the reasons above, we should set vendorChunk as false for build and serve in angular.json

 ...
 "build": {
    "builder": "@angular-builders/custom-webpack:browser",
    "options": {
          "customWebpackConfig": {
              "path": "./examples/app2/extra-webpack.config.js",
              "mergeStrategies": {
                "module.rules": "prepend"
              },
              "replaceDuplicatePlugins": true
          },
          ...
          "vendorChunk": false,
          ...
      },
  },
  "serve": {
      "builder": "@angular-builders/custom-webpack:dev-server",
      "options": {
          ...
          "vendorChunk": false
          ...
      }
  }
...

throw error An accessor cannot be declared in an ambient context.

this is TypeScript's issue, details see an-accessor-cannot-be-declared should setting skipLibCheck as true

"compilerOptions": {
    "skipLibCheck": true
}

Development

npm run start // open http://localhost:3000

or

npm run serve:portal // 3000
npm run serve:app1 // 3001
npm run serve:app2 // 3002

// test
npm run test

Roadmap

  • [ ] Ivy render engine
  • [ ] Supports Other frameworks as React and Vue

Contributors ✨

Thanks goes to these wonderful people (emoji key):


why520crazy

💬 💼 💻 🎨 📖 📋 🚇 🚧 📆 👀

Walker

💻 💡 🚧 👀

whyour

💻

张威

💻

luxiaobei

🚇 ⚠️ 💻

mario_ma

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].