diff --git a/README.md b/README.md index 2f94745..5095d54 100644 --- a/README.md +++ b/README.md @@ -104,14 +104,8 @@ export class AppComponent implements OnInit { hostParent: '#app-host-container', hostClass: 'thy-layout', routerPathPrefix: '/app1', - resourcePathPrefix: '/static/app1', preload: true, - scripts: [ - 'main.js' - ], - styles: [ - 'styles.css' - ] + entry: "/static/app2/index.html" }, { name: 'app2', @@ -119,12 +113,16 @@ export class AppComponent implements OnInit { hostClass: 'thy-layout', routerPathPrefix: '/app2', preload: true, - scripts: [ - '/static/app2/main.js' - ], - styles: [ - '/static/app2/styles.css' - ] + entry: { + basePath: "/static/app1/" + manifest: "index.html" + scripts: [ + 'main.js' + ], + styles: [ + 'styles.css' + ] + } } ]); @@ -195,20 +193,21 @@ defineApplication('standalone-app', { ### 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 之后的命名,需要动态获取 | +| Name | Type | Description | 中文描述 | +| ------- | -------- | ----------| -------------- | +| name | string | Application's name | 子应用的名字 | +| routerPathPrefix | string | Application route path prefix | 子应用路由路径前缀,根据这个匹配应用 | +| selector | string | selector of app root component | 子应用的启动组件选择器,因为子应用是主应用动态加载的,所以主应用需要先创建这个选择器节点,再启动 AppModule | +| entry | string \| PlanetApplicationEntry | entry for micro app, contains manifest, scripts, styles | 入口配置,如果是字符串表示应用入口 index.html,如果是对象, manifest 为入口 html 或者 json 文件地址,scripts 和 styles 为指定的资源列表,未指定使用 manifest 接口中返回的所有资源,basePath 为基本路由,所有的资源请求地址前会带上 basePath | +| manifest | string | manifest json file path `deprecated` please use entry | manifest.json 文件路径地址,当设置了路径后会先加载这个文件,然后根据 scripts 和 styles 文件名去找到匹配的文件,因为生产环境的静态资文件是 hash 之后的命名,需要动态获取 | +| scripts | string[] | javascript static resource paths `deprecated` please use entry.scripts | JS 静态资源文件访问地址 | +| styles | string[] | style static resource paths `deprecated` please use entry.styles | 样式静态资源文件访问地址 | +| resourcePathPrefix | string | path prefix of scripts and styles `deprecated` please use entry.basePath | 脚本和样式文件路径前缀,多个脚本可以避免重复写同样的前缀 | +| 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 | 是否串行加载脚本静态资源 | ### Communication between applications use GlobalEventDispatcher diff --git a/examples/portal/src/app/app.component.ts b/examples/portal/src/app/app.component.ts index c25d996..da8e97f 100644 --- a/examples/portal/src/app/app.component.ts +++ b/examples/portal/src/app/app.component.ts @@ -100,16 +100,17 @@ export class AppComponent implements OnInit { hostParent: '#app-host-container', hostClass: appHostClass, routerPathPrefix: '/standalone-app', - resourcePathPrefix: '/static/standalone-app/', preload: settings.standaloneApp?.preload, switchMode: settings.standaloneApp?.switchMode, stylePrefix: 'standalone-app', - // prettier-ignore - scripts: [ - 'main.js' - ], - styles: ['styles.css'], - manifest: '/static/standalone-app/assets-manifest.json', + entry: '/static/standalone-app/index.html', + // resourcePathPrefix: '/static/standalone-app/', + // // prettier-ignore + // scripts: [ + // 'main.js' + // ], + // styles: ['styles.css'], + // manifest: '/static/standalone-app/index.html', extra: { name: '独立应用', color: '#66c060' diff --git a/packages/planet/src/assets-loader.spec.ts b/packages/planet/src/assets-loader.spec.ts index 429ce9f..cedb039 100644 --- a/packages/planet/src/assets-loader.spec.ts +++ b/packages/planet/src/assets-loader.spec.ts @@ -4,6 +4,7 @@ import { AssetsLoader, AssetsLoadResult } from './assets-loader'; import { hashCode } from './helpers'; import { Subject, of, observable, Observable, BehaviorSubject } from 'rxjs'; import { HttpClient } from '@angular/common/http'; +import { PlanetApplication, PlanetApplicationEntry } from './planet.class'; describe('assets-loader', () => { let assetsLoader: AssetsLoader; @@ -12,6 +13,23 @@ describe('assets-loader', () => { onerror: (error: string | Event) => void; } = { onload: () => {}, onerror: null }; + const html = ` + +
+ + + +