@worktile/planet 10.0.0 → 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.all-contributorsrc +84 -0
- package/.circleci/config.yml +17 -0
- package/.coveralls.yml +1 -0
- package/.docgeni/public/assets/favicon.ico +0 -0
- package/.docgeni/public/index.html +13 -0
- package/.docgenirc.js +35 -0
- package/.dockerignore +1 -0
- package/.editorconfig +22 -0
- package/.github/FUNDING.yml +12 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.prettierignore +7 -0
- package/.prettierrc +28 -0
- package/.travis.yml +26 -0
- package/.wpmrc.js +11 -0
- package/CHANGELOG.md +391 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/Dockerfile +11 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/README.zh-CN.md +307 -0
- package/SECURITY.md +21 -0
- package/angular.json +373 -0
- package/commitlint.config.js +6 -0
- package/docs/api/defineApplication.md +46 -0
- package/docs/api/globalEventDispatcher.md +51 -0
- package/docs/api/index.md +5 -0
- package/docs/api/planet.md +117 -0
- package/docs/guides/getting-started.md +174 -0
- package/docs/guides/index.md +5 -0
- package/docs/guides/intro.md +216 -0
- package/examples/app1/browserslist +11 -0
- package/examples/app1/extra-webpack.config.js +33 -0
- package/examples/app1/karma.conf.js +31 -0
- package/examples/app1/postcss.config.js +1 -0
- package/examples/app1/src/app/app.module.ts +44 -0
- package/examples/app1/src/app/app.routing.ts +49 -0
- package/examples/app1/src/app/counter.service.ts +16 -0
- package/examples/app1/src/app/dashboard/dashboard.component.html +51 -0
- package/examples/app1/src/app/dashboard/dashboard.component.ts +70 -0
- package/examples/app1/src/app/detail/detail.component.html +8 -0
- package/examples/app1/src/app/detail/detail.component.ts +18 -0
- package/examples/app1/src/app/overlay.ts +26 -0
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +10 -0
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +41 -0
- package/examples/app1/src/app/projects/projects.component.ts +33 -0
- package/examples/app1/src/app/root/root.component.css +3 -0
- package/examples/app1/src/app/root/root.component.html +16 -0
- package/examples/app1/src/app/root/root.component.ts +35 -0
- package/examples/app1/src/app/services/initialized-data.resolver.ts +15 -0
- package/examples/app1/src/app/shared.module.ts +57 -0
- package/examples/app1/src/app/user/detail/user-detail.component.html +5 -0
- package/examples/app1/src/app/user/detail/user-detail.component.ts +20 -0
- package/examples/app1/src/app/user/user-list.component.html +7 -0
- package/examples/app1/src/app/user/user-list.component.ts +20 -0
- package/examples/app1/src/app/user/user.module.ts +31 -0
- package/examples/app1/src/assets/.gitkeep +0 -0
- package/examples/app1/src/assets/github.png +0 -0
- package/examples/app1/src/assets/main.css +3 -0
- package/examples/app1/src/environments/environment.prod.ts +3 -0
- package/examples/app1/src/environments/environment.ts +16 -0
- package/examples/app1/src/favicon.ico +0 -0
- package/examples/app1/src/index.html +14 -0
- package/examples/app1/src/main.ts +35 -0
- package/examples/app1/src/polyfills.ts +84 -0
- package/examples/app1/src/styles.scss +35 -0
- package/examples/app1/src/test.ts +14 -0
- package/examples/app1/temp.js +221 -0
- package/examples/app1/tsconfig.app.json +10 -0
- package/examples/app1/tsconfig.spec.json +18 -0
- package/examples/app1/tslint.json +17 -0
- package/examples/app1/webpack.config.js +127 -0
- package/examples/app2/browserslist +11 -0
- package/examples/app2/extra-webpack.config.js +32 -0
- package/examples/app2/karma.conf.js +31 -0
- package/examples/app2/src/app/app.module.ts +90 -0
- package/examples/app2/src/app/dashboard/dashboard.component.html +21 -0
- package/examples/app2/src/app/dashboard/dashboard.component.ts +27 -0
- package/examples/app2/src/app/overlay.ts +26 -0
- package/examples/app2/src/app/projects/detail/detail.component.html +16 -0
- package/examples/app2/src/app/projects/detail/detail.component.ts +21 -0
- package/examples/app2/src/app/projects/project-list.component.html +29 -0
- package/examples/app2/src/app/projects/project-list.component.ts +58 -0
- package/examples/app2/src/app/projects/project.resolver.ts +15 -0
- package/examples/app2/src/app/projects/projects.service.ts +28 -0
- package/examples/app2/src/app/projects/tasks/tasks.component.html +10 -0
- package/examples/app2/src/app/projects/tasks/tasks.component.ts +16 -0
- package/examples/app2/src/app/projects/view/view.component.html +1 -0
- package/examples/app2/src/app/projects/view/view.component.ts +20 -0
- package/examples/app2/src/app/root/root.component.html +14 -0
- package/examples/app2/src/app/root/root.component.scss +12 -0
- package/examples/app2/src/app/root/root.component.ts +28 -0
- package/examples/app2/src/app/shared.module.ts +59 -0
- package/examples/app2/src/assets/.gitkeep +0 -0
- package/examples/app2/src/environments/environment.prod.ts +3 -0
- package/examples/app2/src/environments/environment.ts +16 -0
- package/examples/app2/src/favicon.ico +0 -0
- package/examples/app2/src/index.html +14 -0
- package/examples/app2/src/main.ts +36 -0
- package/examples/app2/src/polyfills.ts +84 -0
- package/examples/app2/src/styles.scss +28 -0
- package/examples/app2/src/test.ts +14 -0
- package/examples/app2/tsconfig.app.json +10 -0
- package/examples/app2/tsconfig.spec.json +18 -0
- package/examples/app2/tslint.json +7 -0
- package/examples/app2/webpack.config.js +92 -0
- package/examples/common/app-root-context.ts +10 -0
- package/examples/common/cache.ts +82 -0
- package/examples/common/index.ts +13 -0
- package/examples/common/module.ts +10 -0
- package/examples/common/overlay-container.service.ts +28 -0
- package/examples/common/section-card/section-card.component.html +5 -0
- package/examples/common/section-card/section-card.component.scss +15 -0
- package/examples/common/section-card/section-card.component.ts +11 -0
- package/examples/common/utils.ts +0 -0
- package/examples/portal/src/app/a-detail/a-detail.component.html +8 -0
- package/examples/portal/src/app/a-detail/a-detail.component.ts +18 -0
- package/examples/portal/src/app/about/about.component.html +27 -0
- package/examples/portal/src/app/about/about.component.scss +0 -0
- package/examples/portal/src/app/about/about.component.spec.ts +26 -0
- package/examples/portal/src/app/about/about.component.ts +26 -0
- package/examples/portal/src/app/app-routing.module.ts +57 -0
- package/examples/portal/src/app/app.component.html +73 -0
- package/examples/portal/src/app/app.component.scss +58 -0
- package/examples/portal/src/app/app.component.spec.ts +33 -0
- package/examples/portal/src/app/app.component.ts +111 -0
- package/examples/portal/src/app/app.module.ts +64 -0
- package/examples/portal/src/app/custom-settings.service.ts +44 -0
- package/examples/portal/src/app/overlay.ts +26 -0
- package/examples/portal/src/app/settings/settings.component.html +31 -0
- package/examples/portal/src/app/settings/settings.component.scss +3 -0
- package/examples/portal/src/app/settings/settings.component.ts +43 -0
- package/examples/portal/src/assets/.gitkeep +0 -0
- package/examples/portal/src/assets/apps.json +29 -0
- package/examples/portal/src/assets/icons/sprite.defs.svg +1 -0
- package/examples/portal/src/assets/images/logo.svg +16 -0
- package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
- package/examples/portal/src/browserslist +11 -0
- package/examples/portal/src/environments/environment.prod.ts +3 -0
- package/examples/portal/src/environments/environment.ts +16 -0
- package/examples/portal/src/extra-webpack.config.js +32 -0
- package/examples/portal/src/favicon.ico +0 -0
- package/examples/portal/src/index.html +14 -0
- package/examples/portal/src/karma.conf.js +31 -0
- package/examples/portal/src/main.ts +18 -0
- package/examples/portal/src/polyfills.ts +84 -0
- package/examples/portal/src/reboot.scss +14 -0
- package/examples/portal/src/styles.scss +14 -0
- package/examples/portal/src/test.ts +14 -0
- package/examples/portal/src/tsconfig.app.json +10 -0
- package/examples/portal/src/tsconfig.spec.json +9 -0
- package/examples/portal/src/tslint.json +7 -0
- package/extra-webpack.config.js +5 -0
- package/nginx.conf +17 -0
- package/package.json +120 -15
- package/packages/planet/karma.conf.js +37 -0
- package/packages/planet/ng-package.json +7 -0
- package/packages/planet/package.json +10 -0
- package/packages/planet/src/application/planet-application-loader.spec.ts +1102 -0
- package/packages/planet/src/application/planet-application-loader.ts +549 -0
- package/packages/planet/src/application/planet-application-ref.spec.ts +233 -0
- package/packages/planet/src/application/planet-application-ref.ts +131 -0
- package/packages/planet/src/application/planet-application.service.spec.ts +145 -0
- package/packages/planet/src/application/planet-application.service.ts +88 -0
- package/packages/planet/src/application/portal-application.spec.ts +53 -0
- package/packages/planet/src/application/portal-application.ts +28 -0
- package/packages/planet/src/assets-loader.spec.ts +689 -0
- package/packages/planet/src/assets-loader.ts +247 -0
- package/packages/planet/src/component/planet-component-loader.spec.ts +187 -0
- package/packages/planet/src/component/planet-component-loader.ts +173 -0
- package/{component/planet-component-ref.d.ts → packages/planet/src/component/planet-component-ref.ts} +3 -2
- package/{component/plant-component.config.d.ts → packages/planet/src/component/plant-component.config.ts} +4 -3
- package/packages/planet/src/debug.spec.ts +58 -0
- package/packages/planet/src/debug.ts +66 -0
- package/packages/planet/src/empty/empty.component.spec.ts +34 -0
- package/packages/planet/src/empty/empty.component.ts +7 -0
- package/packages/planet/src/global-event-dispatcher.spec.ts +81 -0
- package/packages/planet/src/global-event-dispatcher.ts +82 -0
- package/packages/planet/src/global-planet.spec.ts +39 -0
- package/packages/planet/src/global-planet.ts +73 -0
- package/packages/planet/src/helpers.spec.ts +242 -0
- package/packages/planet/src/helpers.ts +125 -0
- package/packages/planet/src/module.spec.ts +79 -0
- package/packages/planet/src/module.ts +25 -0
- package/packages/planet/src/planet.class.ts +59 -0
- package/packages/planet/src/planet.spec.ts +226 -0
- package/packages/planet/src/planet.ts +113 -0
- package/{public-api.d.ts → packages/planet/src/public-api.ts} +4 -0
- package/packages/planet/src/sandbox/constants.ts +6 -0
- package/packages/planet/src/sandbox/exec.ts +22 -0
- package/packages/planet/src/sandbox/index.ts +24 -0
- package/packages/planet/src/sandbox/proxy/patches/document.ts +13 -0
- package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +49 -0
- package/packages/planet/src/sandbox/proxy/patches/index.ts +13 -0
- package/packages/planet/src/sandbox/proxy/patches/storage.ts +53 -0
- package/packages/planet/src/sandbox/proxy/patches/timer.ts +50 -0
- package/packages/planet/src/sandbox/proxy/proxies/common.ts +137 -0
- package/packages/planet/src/sandbox/proxy/proxies/document.ts +140 -0
- package/packages/planet/src/sandbox/proxy/proxies/window.ts +176 -0
- package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +59 -0
- package/packages/planet/src/sandbox/proxy/types.ts +20 -0
- package/packages/planet/src/sandbox/sandbox.ts +20 -0
- package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +12 -0
- package/packages/planet/src/sandbox/types.ts +1 -0
- package/packages/planet/src/test.ts +16 -0
- package/packages/planet/src/testing/app1.module.ts +34 -0
- package/packages/planet/src/testing/app2.module.ts +24 -0
- package/packages/planet/src/testing/applications.ts +58 -0
- package/packages/planet/src/testing/index.ts +2 -0
- package/packages/planet/src/testing/utils.ts +31 -0
- package/packages/planet/tsconfig.lib.json +27 -0
- package/packages/planet/tsconfig.lib.prod.json +9 -0
- package/packages/planet/tsconfig.spec.json +17 -0
- package/packages/planet/tslint.json +7 -0
- package/postcss.config.js +3 -0
- package/proxy.conf.js +15 -0
- package/tsconfig.json +23 -0
- package/tslint.json +80 -0
- package/application/planet-application-loader.d.ts +0 -68
- package/application/planet-application-ref.d.ts +0 -32
- package/application/planet-application.service.d.ts +0 -18
- package/application/portal-application.d.ts +0 -14
- package/assets-loader.d.ts +0 -23
- package/bundles/worktile-planet.umd.js +0 -1670
- package/bundles/worktile-planet.umd.js.map +0 -1
- package/bundles/worktile-planet.umd.min.js +0 -16
- package/bundles/worktile-planet.umd.min.js.map +0 -1
- package/component/planet-component-loader.d.ts +0 -27
- package/empty/empty.component.d.ts +0 -2
- package/esm2015/application/planet-application-loader.js +0 -417
- package/esm2015/application/planet-application-ref.js +0 -86
- package/esm2015/application/planet-application.service.js +0 -87
- package/esm2015/application/portal-application.js +0 -16
- package/esm2015/assets-loader.js +0 -165
- package/esm2015/component/planet-component-loader.js +0 -157
- package/esm2015/component/planet-component-ref.js +0 -3
- package/esm2015/component/plant-component.config.js +0 -7
- package/esm2015/empty/empty.component.js +0 -10
- package/esm2015/global-event-dispatcher.js +0 -71
- package/esm2015/global-planet.js +0 -51
- package/esm2015/helpers.js +0 -116
- package/esm2015/module.js +0 -27
- package/esm2015/planet.class.js +0 -9
- package/esm2015/planet.js +0 -86
- package/esm2015/public-api.js +0 -18
- package/esm2015/worktile-planet.js +0 -6
- package/fesm2015/worktile-planet.js +0 -1257
- package/fesm2015/worktile-planet.js.map +0 -1
- package/global-event-dispatcher.d.ts +0 -19
- package/global-planet.d.ts +0 -22
- package/helpers.d.ts +0 -37
- package/module.d.ts +0 -5
- package/planet.class.d.ts +0 -34
- package/planet.d.ts +0 -24
- package/worktile-planet.d.ts +0 -5
- package/worktile-planet.metadata.json +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# ngx-planet
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/worktile/ngx-planet)
|
|
4
|
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
|
5
|
+
[](https://www.npmjs.com/package/@worktile/planet)
|
|
6
|
+
[](https://www.npmjs.com/package/@worktile/planet)
|
|
7
|
+
 [](#contributors-)
|
|
8
|
+
|
|
9
|
+
[coveralls-image]: https://coveralls.io/repos/github/worktile/ngx-planet/badge.svg?branch=master
|
|
10
|
+
[coveralls-url]: https://coveralls.io/github/worktile/ngx-planet
|
|
11
|
+
|
|
12
|
+
A powerful, reliable, fully-featured and production ready Micro Frontend library for Angular.
|
|
13
|
+
|
|
14
|
+
APIs consistent with angular style, currently only supports Angular, other frameworks are not supported.
|
|
15
|
+
|
|
16
|
+
English | [中文文档](https://github.com/worktile/ngx-planet/blob/master/README.zh-CN.md)
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- Rendering multiple applications at the same time
|
|
21
|
+
- Support two mode, coexist and default that switch to another app and destroy active apps
|
|
22
|
+
- Support application preload
|
|
23
|
+
- Support style isolation
|
|
24
|
+
- Built-in communication between multiple applications
|
|
25
|
+
- Cross application component rendering
|
|
26
|
+
- Comprehensive examples include routing configuration, lazy loading and all features
|
|
27
|
+
|
|
28
|
+
## Alternatives
|
|
29
|
+
|
|
30
|
+
- [single-spa](https://github.com/CanopyTax/single-spa): A javascript front-end framework supports any frameworks.
|
|
31
|
+
- [mooa](https://github.com/phodal/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.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
$ npm i @worktile/planet --save
|
|
37
|
+
// or
|
|
38
|
+
$ yarn add @worktile/planet
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Dependencies
|
|
42
|
+
|
|
43
|
+
- `@angular/cdk`, you should install `@angular/cdk`
|
|
44
|
+
|
|
45
|
+
## Demo
|
|
46
|
+
|
|
47
|
+
[Try out our live demo](http://planet.ngnice.com)
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
### 1. Loading NgxPlanetModule in the portal's AppModule
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
import { NgxPlanetModule } from '@worktile/planet';
|
|
57
|
+
|
|
58
|
+
@NgModule({
|
|
59
|
+
imports: [
|
|
60
|
+
CommonModule,
|
|
61
|
+
NgxPlanetModule
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
class AppModule {}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Register applications to planet use PlanetService in portal app
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
@Component({
|
|
71
|
+
selector: 'app-portal-root',
|
|
72
|
+
template: `
|
|
73
|
+
<nav>
|
|
74
|
+
<a [routerLink]="['/app1']" routerLinkActive="active">应用1</a>
|
|
75
|
+
<a [routerLink]="['/app2']" routerLinkActive="active">应用2</a>
|
|
76
|
+
</nav>
|
|
77
|
+
<router-outlet></router-outlet>
|
|
78
|
+
<div id="app-host-container"></div>
|
|
79
|
+
<div *ngIf="!loadingDone">加载中...</div>
|
|
80
|
+
`
|
|
81
|
+
})
|
|
82
|
+
export class AppComponent implements OnInit {
|
|
83
|
+
title = 'ngx-planet';
|
|
84
|
+
|
|
85
|
+
get loadingDone() {
|
|
86
|
+
return this.planet.loadingDone;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
constructor(
|
|
90
|
+
private planet: Planet
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
ngOnInit() {
|
|
94
|
+
this.planet.setOptions({
|
|
95
|
+
switchMode: SwitchModes.coexist,
|
|
96
|
+
errorHandler: error => {
|
|
97
|
+
console.error(`Failed to load resource, error:`, error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
this.planet.registerApps([
|
|
102
|
+
{
|
|
103
|
+
name: 'app1',
|
|
104
|
+
hostParent: '#app-host-container',
|
|
105
|
+
hostClass: 'thy-layout',
|
|
106
|
+
routerPathPrefix: '/app1',
|
|
107
|
+
resourcePathPrefix: '/static/app1',
|
|
108
|
+
preload: true,
|
|
109
|
+
scripts: [
|
|
110
|
+
'main.js'
|
|
111
|
+
],
|
|
112
|
+
styles: [
|
|
113
|
+
'styles.css'
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'app2',
|
|
118
|
+
hostParent: '#app-host-container',
|
|
119
|
+
hostClass: 'thy-layout',
|
|
120
|
+
routerPathPrefix: '/app2',
|
|
121
|
+
preload: true,
|
|
122
|
+
scripts: [
|
|
123
|
+
'/static/app2/main.js'
|
|
124
|
+
],
|
|
125
|
+
styles: [
|
|
126
|
+
'/static/app2/styles.css'
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
// start monitor route changes
|
|
132
|
+
// get apps to active by current path
|
|
133
|
+
// load static resources which contains javascript and css
|
|
134
|
+
// bootstrap angular sub app module and show it
|
|
135
|
+
this.planet.start();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 3. Sub App define how to bootstrap AppModule
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
defineApplication('app1', {
|
|
144
|
+
template: `<app1-root class="app1-root"></app1-root>`,
|
|
145
|
+
bootstrap: (portalApp: PlanetPortalApplication) => {
|
|
146
|
+
return platformBrowserDynamic([
|
|
147
|
+
{
|
|
148
|
+
provide: PlanetPortalApplication,
|
|
149
|
+
useValue: portalApp
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
provide: AppRootContext,
|
|
153
|
+
useValue: portalApp.data.appRootContext
|
|
154
|
+
}
|
|
155
|
+
])
|
|
156
|
+
.bootstrapModule(AppModule)
|
|
157
|
+
.then(appModule => {
|
|
158
|
+
return appModule;
|
|
159
|
+
})
|
|
160
|
+
.catch(error => {
|
|
161
|
+
console.error(error);
|
|
162
|
+
return null;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Documents
|
|
169
|
+
|
|
170
|
+
### Sub app configurations
|
|
171
|
+
|
|
172
|
+
| Name | Type | Description | 中文描述 |
|
|
173
|
+
| ------------------ | --------------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| name | string | Application's name | 子应用的名字 |
|
|
175
|
+
| routerPathPrefix | string | Application route path prefix | 子应用路由路径前缀,根据这个匹配应用 |
|
|
176
|
+
| selector | string | selector of app root component | 子应用的启动组件选择器,因为子应用是主应用动态加载的,所以主应用需要先创建这个选择器节点,再启动 AppModule |
|
|
177
|
+
| scripts | string[] | javascript static resource paths | JS 静态资源文件访问地址 |
|
|
178
|
+
| styles | string[] | style static resource paths | 样式静态资源文件访问地址 |
|
|
179
|
+
| resourcePathPrefix | string | path prefix of scripts and styles | 脚本和样式文件路径前缀,多个脚本可以避免重复写同样的前缀 |
|
|
180
|
+
| hostParent | string or HTMLElement | parent element for render | 应用渲染的容器元素, 指定子应用显示在哪个元素内部 |
|
|
181
|
+
| hostClass | string | added class for host which is selector | 宿主元素的 Class,也就是在子应用启动组件上追加的样式 |
|
|
182
|
+
| switchMode | default or coexist | it will be destroyed when set to default, it only hide app when set to coexist | 切换子应用的模式,默认切换会销毁,设置 coexist 后只会隐藏 |
|
|
183
|
+
| preload | boolean | start preload or not | 是否启用预加载,启动后刷新页面等当前页面的应用渲染完毕后预加载子应用 |
|
|
184
|
+
| loadSerial | boolean | serial load scripts | 是否串行加载脚本静态资源 |
|
|
185
|
+
| manifest | string | manifest json file path | manifest.json 文件路径地址,当设置了路径后会先加载这个文件,然后根据 scripts 和 styles 文件名去找到匹配的文件,因为生产环境的静态资文件是 hash 之后的命名,需要动态获取 |
|
|
186
|
+
|
|
187
|
+
### Communication between applications use GlobalEventDispatcher
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
import { GlobalEventDispatcher } from "@worktile/planet";
|
|
191
|
+
|
|
192
|
+
// app1 root module
|
|
193
|
+
export class AppModule {
|
|
194
|
+
constructor(private globalEventDispatcher: GlobalEventDispatcher) {
|
|
195
|
+
this.globalEventDispatcher.register('open-a-detail').subscribe(event => {
|
|
196
|
+
// dialog.open(App1DetailComponent);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// in other apps
|
|
202
|
+
export class OneComponent {
|
|
203
|
+
constructor(private globalEventDispatcher: GlobalEventDispatcher) {
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
openDetail() {
|
|
207
|
+
this.globalEventDispatcher.dispatch('open-a-detail', payload);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Cross application component rendering
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
import { PlanetComponentLoader } from "@worktile/planet";
|
|
216
|
+
|
|
217
|
+
// in app1
|
|
218
|
+
export class AppModule {
|
|
219
|
+
constructor(private planetComponentLoader: PlanetComponentLoader) {
|
|
220
|
+
this.planetComponentLoader.register([{ name: 'app1-project-list', component: App1ProjectListComponent }]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// in other apps
|
|
225
|
+
export class OneComponent {
|
|
226
|
+
constructor(private planetComponentLoader: PlanetComponentLoader) {
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
openDetail() {
|
|
230
|
+
this.planetComponentLoader.load('app1', 'app1-project-list', {
|
|
231
|
+
container: this.containerElementRef,
|
|
232
|
+
initialState: {}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## FAQ
|
|
240
|
+
|
|
241
|
+
### infinite loop load portal app's js
|
|
242
|
+
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.
|
|
243
|
+
```
|
|
244
|
+
// extra-webpack.config.js
|
|
245
|
+
{
|
|
246
|
+
optimization: {
|
|
247
|
+
runtimeChunk: false
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### throw error `Cannot read property 'call' of undefined at __webpack_require__ (bootstrap:79)`
|
|
253
|
+
Similar to the reasons above, we should set `vendorChunk` as `false` for `build` and `serve` in `angular.json`
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
...
|
|
257
|
+
"build": {
|
|
258
|
+
"builder": "@angular-builders/custom-webpack:browser",
|
|
259
|
+
"options": {
|
|
260
|
+
"customWebpackConfig": {
|
|
261
|
+
"path": "./examples/app2/extra-webpack.config.js",
|
|
262
|
+
"mergeStrategies": {
|
|
263
|
+
"module.rules": "prepend"
|
|
264
|
+
},
|
|
265
|
+
"replaceDuplicatePlugins": true
|
|
266
|
+
},
|
|
267
|
+
...
|
|
268
|
+
"vendorChunk": false,
|
|
269
|
+
...
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
"serve": {
|
|
273
|
+
"builder": "@angular-builders/custom-webpack:dev-server",
|
|
274
|
+
"options": {
|
|
275
|
+
...
|
|
276
|
+
"vendorChunk": false
|
|
277
|
+
...
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
...
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### throw error `An accessor cannot be declared in an ambient context.`
|
|
284
|
+
this is TypeScript's issue, details see [an-accessor-cannot-be-declared](https://stackoverflow.com/questions/61248058/error-ngx-daterangepicker-material-an-accessor-cannot-be-declared-in-an-ambient
|
|
285
|
+
)
|
|
286
|
+
should setting `skipLibCheck` as true
|
|
287
|
+
```
|
|
288
|
+
"compilerOptions": {
|
|
289
|
+
"skipLibCheck": true
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Production env throw error `Cannot read property 'call' of undefined` use router lazy load
|
|
294
|
+
|
|
295
|
+
In webpack 4 multiple webpack runtimes could conflict on the same HTML page, because they use the same global variable for chunk loading. To fix that it was needed to provide a custom name to the output.jsonpFunction configuration, details see [Automatic unique naming](https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-unique-naming).
|
|
296
|
+
|
|
297
|
+
you should set a unique name for each sub application in `extra-webpack.config.js`
|
|
298
|
+
```
|
|
299
|
+
output: { jsonpFunction: "app1" }
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Development
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
npm run start // open http://localhost:3000
|
|
306
|
+
|
|
307
|
+
or
|
|
308
|
+
|
|
309
|
+
npm run serve:portal // 3000
|
|
310
|
+
npm run serve:app1 // 3001
|
|
311
|
+
npm run serve:app2 // 3002
|
|
312
|
+
|
|
313
|
+
// test
|
|
314
|
+
npm run test
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Roadmap
|
|
318
|
+
|
|
319
|
+
- [ ] Ivy render engine
|
|
320
|
+
- [ ] Supports Other frameworks as React and Vue
|
|
321
|
+
|
|
322
|
+
## Contributors ✨
|
|
323
|
+
|
|
324
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
325
|
+
|
|
326
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
327
|
+
<!-- prettier-ignore-start -->
|
|
328
|
+
<!-- markdownlint-disable -->
|
|
329
|
+
<table>
|
|
330
|
+
<tr>
|
|
331
|
+
<td align="center"><a href="https://www.zhihu.com/people/why520crazy/activities"><img src="https://avatars2.githubusercontent.com/u/3959960?v=4" width="100px;" alt=""/><br /><sub><b>why520crazy</b></sub></a><br /><a href="#question-why520crazy" title="Answering Questions">💬</a> <a href="#business-why520crazy" title="Business development">💼</a> <a href="https://github.com/worktile/ngx-planet/commits?author=why520crazy" title="Code">💻</a> <a href="#design-why520crazy" title="Design">🎨</a> <a href="https://github.com/worktile/ngx-planet/commits?author=why520crazy" title="Documentation">📖</a> <a href="#eventOrganizing-why520crazy" title="Event Organizing">📋</a> <a href="#infra-why520crazy" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-why520crazy" title="Maintenance">🚧</a> <a href="#projectManagement-why520crazy" title="Project Management">📆</a> <a href="https://github.com/worktile/ngx-planet/pulls?q=is%3Apr+reviewed-by%3Awhy520crazy" title="Reviewed Pull Requests">👀</a></td>
|
|
332
|
+
<td align="center"><a href="https://github.com/walkerkay"><img src="https://avatars1.githubusercontent.com/u/15701592?v=4" width="100px;" alt=""/><br /><sub><b>Walker</b></sub></a><br /><a href="https://github.com/worktile/ngx-planet/commits?author=walkerkay" title="Code">💻</a> <a href="#example-walkerkay" title="Examples">💡</a> <a href="#maintenance-walkerkay" title="Maintenance">🚧</a> <a href="https://github.com/worktile/ngx-planet/pulls?q=is%3Apr+reviewed-by%3Awalkerkay" title="Reviewed Pull Requests">👀</a></td>
|
|
333
|
+
<td align="center"><a href="https://whyour.cn"><img src="https://avatars3.githubusercontent.com/u/22700758?v=4" width="100px;" alt=""/><br /><sub><b>whyour</b></sub></a><br /><a href="https://github.com/worktile/ngx-planet/commits?author=whyour" title="Code">💻</a></td>
|
|
334
|
+
<td align="center"><a href="http://www.231jx.cn"><img src="https://avatars0.githubusercontent.com/u/19969080?v=4" width="100px;" alt=""/><br /><sub><b>张威</b></sub></a><br /><a href="https://github.com/worktile/ngx-planet/commits?author=aoilti" title="Code">💻</a></td>
|
|
335
|
+
<td align="center"><a href="https://github.com/luxiaobei"><img src="https://avatars1.githubusercontent.com/u/13583957?v=4" width="100px;" alt=""/><br /><sub><b>luxiaobei</b></sub></a><br /><a href="#infra-luxiaobei" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/worktile/ngx-planet/commits?author=luxiaobei" title="Tests">⚠️</a> <a href="https://github.com/worktile/ngx-planet/commits?author=luxiaobei" title="Code">💻</a></td>
|
|
336
|
+
<td align="center"><a href="https://github.com/mario56"><img src="https://avatars2.githubusercontent.com/u/7720722?v=4" width="100px;" alt=""/><br /><sub><b>mario_ma</b></sub></a><br /><a href="https://github.com/worktile/ngx-planet/commits?author=mario56" title="Code">💻</a></td>
|
|
337
|
+
</tr>
|
|
338
|
+
</table>
|
|
339
|
+
|
|
340
|
+
<!-- markdownlint-enable -->
|
|
341
|
+
<!-- prettier-ignore-end -->
|
|
342
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
343
|
+
|
|
344
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
|
345
|
+
|
|
346
|
+
## LICENSE
|
|
347
|
+
|
|
348
|
+
[MIT License](https://github.com/worktile/ngx-planet/blob/master/LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# ngx-planet
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/worktile/ngx-planet)
|
|
4
|
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
|
5
|
+
[](https://www.npmjs.com/package/@worktile/planet)
|
|
6
|
+
[](https://www.npmjs.com/package/@worktile/planet)
|
|
7
|
+
 [](#contributors-)
|
|
8
|
+
|
|
9
|
+
[coveralls-image]: https://coveralls.io/repos/github/worktile/ngx-planet/badge.svg?branch=master
|
|
10
|
+
[coveralls-url]: https://coveralls.io/github/worktile/ngx-planet
|
|
11
|
+
|
|
12
|
+
一个强大、可靠、完善、完全可用于生产环境的 Angular 微前端库。
|
|
13
|
+
Angular 的 API 风格,目前只支持 Angular 框架,不支持其他 MV* 前端框架。
|
|
14
|
+
|
|
15
|
+
中文文档 | [English README](https://github.com/worktile/ngx-planet/blob/master/README.md)
|
|
16
|
+
|
|
17
|
+
## 功能
|
|
18
|
+
|
|
19
|
+
- 支持同时渲染多个子应用
|
|
20
|
+
- 支持并存(coexist)和默认(default)两种模式, 默认模式切换其他子应用销毁当前子应用,并存模式不会销毁,而是隐藏
|
|
21
|
+
- 支持子应用的预加载
|
|
22
|
+
- 支持样式隔离
|
|
23
|
+
- 内置多个应用之间的通信
|
|
24
|
+
- 支持跨应用组件的渲染
|
|
25
|
+
- 完善的示例,包含路由配置、懒加载等所有功能
|
|
26
|
+
|
|
27
|
+
## 其他方案
|
|
28
|
+
|
|
29
|
+
- [single-spa](https://github.com/CanopyTax/single-spa): A javascript front-end framework supports any frameworks.
|
|
30
|
+
- [mooa](https://github.com/phodal/mooa): A independent-deployment micro-frontend Framework for Angular from single-spa, `planet` 和 `mooa` 非常相似, 但是 `planet` 更加强大、可靠,同时完全用于了生产环境,比如:https://pingcode.com
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
$ npm i @worktile/planet --save
|
|
36
|
+
// 或者
|
|
37
|
+
$ yarn add @worktile/planet
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Dependencies
|
|
41
|
+
|
|
42
|
+
- `@angular/cdk`, 确保安装了 Angular 官方的 CDK `npm i @angular/cdk --save` 或者 `yarn add @angular/cdk`
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## 示例
|
|
46
|
+
|
|
47
|
+
[Try out our live demo](http://planet.ngnice.com)
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
## 使用说明
|
|
52
|
+
|
|
53
|
+
### 1. 在主应用的`AppModule`中引入`NgxPlanetModule`
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
import { NgxPlanetModule } from '@worktile/planet';
|
|
57
|
+
|
|
58
|
+
@NgModule({
|
|
59
|
+
imports: [
|
|
60
|
+
CommonModule,
|
|
61
|
+
NgxPlanetModule
|
|
62
|
+
]
|
|
63
|
+
})
|
|
64
|
+
class AppModule {}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. 通过`Planet`服务在主应用中注册子应用
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
@Component({
|
|
71
|
+
selector: 'app-portal-root',
|
|
72
|
+
template: `
|
|
73
|
+
<nav>
|
|
74
|
+
<a [routerLink]="['/app1']" routerLinkActive="active">应用1</a>
|
|
75
|
+
<a [routerLink]="['/app2']" routerLinkActive="active">应用2</a>
|
|
76
|
+
</nav>
|
|
77
|
+
<router-outlet></router-outlet>
|
|
78
|
+
<div id="app-host-container"></div>
|
|
79
|
+
<div *ngIf="!loadingDone">加载中...</div>
|
|
80
|
+
`
|
|
81
|
+
})
|
|
82
|
+
export class AppComponent implements OnInit {
|
|
83
|
+
title = 'ngx-planet';
|
|
84
|
+
|
|
85
|
+
get loadingDone() {
|
|
86
|
+
return this.planet.loadingDone;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
constructor(
|
|
90
|
+
private planet: Planet
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
ngOnInit() {
|
|
94
|
+
this.planet.setOptions({
|
|
95
|
+
switchMode: SwitchModes.coexist,
|
|
96
|
+
errorHandler: error => {
|
|
97
|
+
console.error(`Failed to load resource, error:`, error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
this.planet.registerApps([
|
|
102
|
+
{
|
|
103
|
+
name: 'app1',
|
|
104
|
+
hostParent: '#app-host-container',
|
|
105
|
+
hostClass: 'thy-layout',
|
|
106
|
+
routerPathPrefix: '/app1',
|
|
107
|
+
resourcePathPrefix: '/static/app1',
|
|
108
|
+
preload: true,
|
|
109
|
+
scripts: [
|
|
110
|
+
'main.js'
|
|
111
|
+
],
|
|
112
|
+
styles: [
|
|
113
|
+
'styles.css'
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'app2',
|
|
118
|
+
hostParent: '#app-host-container',
|
|
119
|
+
hostClass: 'thy-layout',
|
|
120
|
+
routerPathPrefix: '/app2',
|
|
121
|
+
preload: true,
|
|
122
|
+
scripts: [
|
|
123
|
+
'/static/app2/main.js'
|
|
124
|
+
],
|
|
125
|
+
styles: [
|
|
126
|
+
'/static/app2/styles.css'
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
// start monitor route changes
|
|
132
|
+
// get apps to active by current path
|
|
133
|
+
// load static resources which contains javascript and css
|
|
134
|
+
// bootstrap angular sub app module and show it
|
|
135
|
+
this.planet.start();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 3. 子应用通过`defineApplication`定义如何启动子应用的`AppModule`, 同时可以设置`PlanetPortalApplication`服务为主应用的全局服务。
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
defineApplication('app1', (portalApp: PlanetPortalApplication) => {
|
|
144
|
+
return platformBrowserDynamic([
|
|
145
|
+
{
|
|
146
|
+
provide: PlanetPortalApplication,
|
|
147
|
+
useValue: portalApp
|
|
148
|
+
}
|
|
149
|
+
])
|
|
150
|
+
.bootstrapModule(AppModule)
|
|
151
|
+
.then(appModule => {
|
|
152
|
+
return appModule;
|
|
153
|
+
})
|
|
154
|
+
.catch(error => {
|
|
155
|
+
console.error(error);
|
|
156
|
+
return null;
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 文档
|
|
162
|
+
|
|
163
|
+
### 子应用
|
|
164
|
+
|
|
165
|
+
| Name | Type | Description | 中文描述 |
|
|
166
|
+
| ------------------ | --------------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
167
|
+
| name | string | Application's name | 子应用的名字 |
|
|
168
|
+
| routerPathPrefix | string | Application route path prefix | 子应用路由路径前缀,根据这个匹配应用 |
|
|
169
|
+
| selector | string | selector of app root component | 子应用的启动组件选择器,因为子应用是主应用动态加载的,所以主应用需要先创建这个选择器节点,再启动 AppModule |
|
|
170
|
+
| scripts | string[] | javascript static resource paths | JS 静态资源文件访问地址 |
|
|
171
|
+
| styles | string[] | style static resource paths | 样式静态资源文件访问地址 |
|
|
172
|
+
| resourcePathPrefix | string | path prefix of scripts and styles | 脚本和样式文件路径前缀,多个脚本可以避免重复写同样的前缀 |
|
|
173
|
+
| hostParent | string or HTMLElement | parent element for render | 应用渲染的容器元素, 指定子应用显示在哪个元素内部 |
|
|
174
|
+
| hostClass | string | added class for host which is selector | 宿主元素的 Class,也就是在子应用启动组件上追加的样式 |
|
|
175
|
+
| switchMode | default or coexist | it will be destroyed when set to default, it only hide app when set to coexist | 切换子应用的模式,默认切换会销毁,设置 coexist 后只会隐藏 |
|
|
176
|
+
| preload | boolean | start preload or not | 是否启用预加载,启动后刷新页面等当前页面的应用渲染完毕后预加载子应用 |
|
|
177
|
+
| loadSerial | boolean | serial load scripts | 是否串行加载脚本静态资源 |
|
|
178
|
+
| manifest | string | manifest json file path | manifest.json 文件路径地址,当设置了路径后会先加载这个文件,然后根据 scripts 和 styles 文件名去找到匹配的文件,因为生产环境的静态资文件是 hash 之后的命名,需要动态获取 |
|
|
179
|
+
|
|
180
|
+
### `GlobalEventDispatcher` 实现应用之间的通信
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
import { GlobalEventDispatcher } from "@worktile/planet";
|
|
184
|
+
|
|
185
|
+
// app1 root module
|
|
186
|
+
export class AppModule {
|
|
187
|
+
constructor(private globalEventDispatcher: GlobalEventDispatcher) {
|
|
188
|
+
this.globalEventDispatcher.register('open-a-detail').subscribe(event => {
|
|
189
|
+
// dialog.open(App1DetailComponent);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// in other apps
|
|
195
|
+
export class OneComponent {
|
|
196
|
+
constructor(private globalEventDispatcher: GlobalEventDispatcher) {
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
openDetail() {
|
|
200
|
+
this.globalEventDispatcher.dispatch('open-a-detail', payload);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 跨应用组件渲染
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
import { PlanetComponentLoader } from "@worktile/planet";
|
|
209
|
+
|
|
210
|
+
// in app1
|
|
211
|
+
export class AppModule {
|
|
212
|
+
constructor(private planetComponentLoader: PlanetComponentLoader) {
|
|
213
|
+
this.planetComponentLoader.register([{ name: 'app1-project-list', component: App1ProjectListComponent }]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// in other apps
|
|
218
|
+
export class OneComponent {
|
|
219
|
+
constructor(private planetComponentLoader: PlanetComponentLoader) {
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
openDetail() {
|
|
223
|
+
this.planetComponentLoader.load('app1', 'app1-project-list', {
|
|
224
|
+
container: this.containerElementRef,
|
|
225
|
+
initialState: {}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## FAQ
|
|
233
|
+
|
|
234
|
+
### 无限循环加载主应用的js
|
|
235
|
+
因为主应用和子应用都是通过Webpack打包的,打包的版本依赖会有冲突,需要通过`@angular-builders/custom-webpack`插件设置扩展的`Webpack`配置`runtimeChunk`, 期望 Webpack 5 对于微前端支持的更好。
|
|
236
|
+
```
|
|
237
|
+
// extra-webpack.config.js
|
|
238
|
+
{
|
|
239
|
+
optimization: {
|
|
240
|
+
runtimeChunk: false
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 报错 `Cannot read property 'call' of undefined at __webpack_require__ (bootstrap:79)`
|
|
246
|
+
和上面的原因类似,我们需要设置 `vendorChunk` 为 `false`,需要同时设置 `angular.json`中的`build`和`serve`, `serve` 按理说是应该继承 build 的配置的,好像在 Angular 8 中有缺陷,不起作用。
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
...
|
|
250
|
+
"build": {
|
|
251
|
+
"builder": "@angular-builders/custom-webpack:browser",
|
|
252
|
+
"options": {
|
|
253
|
+
"customWebpackConfig": {
|
|
254
|
+
"path": "./examples/app2/extra-webpack.config.js",
|
|
255
|
+
"mergeStrategies": {
|
|
256
|
+
"module.rules": "prepend"
|
|
257
|
+
},
|
|
258
|
+
"replaceDuplicatePlugins": true
|
|
259
|
+
},
|
|
260
|
+
...
|
|
261
|
+
"vendorChunk": false,
|
|
262
|
+
...
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
"serve": {
|
|
266
|
+
"builder": "@angular-builders/custom-webpack:dev-server",
|
|
267
|
+
"options": {
|
|
268
|
+
...
|
|
269
|
+
"vendorChunk": false
|
|
270
|
+
...
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
...
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 报错 `An accessor cannot be declared in an ambient context.`
|
|
277
|
+
这好像是 TypeScript 某个版本的缺陷,详细情况可以查看 see [an-accessor-cannot-be-declared](https://stackoverflow.com/questions/61248058/error-ngx-daterangepicker-material-an-accessor-cannot-be-declared-in-an-ambient
|
|
278
|
+
)
|
|
279
|
+
临时解决通过设置 `skipLibCheck` 为 true,将来升级到高级版本的 TypeScript 可能就自动修复了。
|
|
280
|
+
```
|
|
281
|
+
"compilerOptions": {
|
|
282
|
+
"skipLibCheck": true
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
### 使用路由延迟加载生产环境报错 `Cannot read property 'call' of undefined``
|
|
286
|
+
|
|
287
|
+
在 Webpack 4 中,多个应用的运行时在同一个页面下会有冲突,因为它们使用了相同的全局变量加载 chunk,为了修复这个问题,你需要通过`output.jsonpFunction`配置项提供一个自定义的名字,详细信息参考:[Automatic unique naming](https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-unique-naming).
|
|
288
|
+
|
|
289
|
+
你需要给每一个子应用的 `extra-webpack.config.js` 文件中配置一个唯一的名字
|
|
290
|
+
```
|
|
291
|
+
output: { jsonpFunction: "app1" }
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## 开发
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
npm run start // open http://localhost:3000
|
|
298
|
+
|
|
299
|
+
or
|
|
300
|
+
|
|
301
|
+
npm run serve:portal // 3000
|
|
302
|
+
npm run serve:app1 // 3001
|
|
303
|
+
npm run serve:app2 // 3002
|
|
304
|
+
|
|
305
|
+
// test
|
|
306
|
+
npm run test
|
|
307
|
+
```
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
Use this section to tell people about which versions of your project are
|
|
6
|
+
currently being supported with security updates.
|
|
7
|
+
|
|
8
|
+
| Version | Supported |
|
|
9
|
+
| ------- | ------------------ |
|
|
10
|
+
| 5.1.x | :white_check_mark: |
|
|
11
|
+
| 5.0.x | :x: |
|
|
12
|
+
| 4.0.x | :white_check_mark: |
|
|
13
|
+
| < 4.0 | :x: |
|
|
14
|
+
|
|
15
|
+
## Reporting a Vulnerability
|
|
16
|
+
|
|
17
|
+
Use this section to tell people how to report a vulnerability.
|
|
18
|
+
|
|
19
|
+
Tell them where to go, how often they can expect to get an update on a
|
|
20
|
+
reported vulnerability, what to expect if the vulnerability is accepted or
|
|
21
|
+
declined, etc.
|