0.3.1 • Published 1 year ago
@versea/core v0.3.1
@versea/core
versea 的核心能力,应用注册,加载,切换能力。
安装
npm install --save @versea/core
使用
import { buildProviderModule, IAppService, IStarter, AppLifeCycles } from '@versea/core';
import { Container } from 'inversify';
async function loadScript(url): Promise<void> {
console.log(url);
// ...
await Promise.resolve();
}
// 创建容器
const container = new Container({ defaultScope: 'Singleton' });
// 绑定依赖容器
container.load(buildProviderModule(container));
// 注册子应用
container.get<IAppService>(IAppService).registerApps([
{
name: 'subApp',
routes: [
{
path: 'sub-app',
pathToRegexpOptions: {
end: false,
},
},
],
loadApp: async (): AppLifeCycles => {
await loadScript('http://localhost:3000/static/js/bundle.js');
return (window as any).microApp;
},
},
]);
// 在合适的时机启动 versea
void container.get<IStarter>(IStarter).start();