1.4.33 • Published 2 months ago

@alicloud/alfa-core v1.4.33

Weekly downloads
215
License
MIT
Repository
-
Last release
2 months ago

Alfa Core

符合阿里集团微前端标准 API 的微前端框架 @alicloud/alfa-core

这是一个偏底层的包,建议使用更上层的包以简化开发:

  • @alicloud/alfa-react(适用于 React 项目)

如何使用

引入你的项目

npm i @alicloud/alfa-core --save
# or
yarn add @alicloud/alfa-core --save
# or
tnpm i @alicloud/alfa-core --save

加载和渲染微应用

import React, { useEffect, useRef } from 'react';
import { createMicroApp } from '@alicloud/alfa-core';

// 微应用的资源描述。单独提出来是因为这部分内容一般来自于平台服务,而不会写死在代码中
const exampleAppManifest = {
  "name": "example",
  "entry": {
    "scripts": ["https://example.com/example.js"],
    "styles": ["https://example.com/example.css"]
  }
};

// 主应用使用 React 实现
function HostApp(props) {
  
  const containerEl = useRef(null);
  
  useEffect(() => {

    let exampleApp = {};

    (async () => {
  
      exampleApp = await createMicroApp({
        // 资源描述是微应用至少需要的配置项,更多的配置项参考 API 文档
        ...exampleAppManifest
      });
  
      // 加载
      await exampleApp.load();
  
      // 渲染
      await exampleApp.mount(containerEl.current, {
        title: `${props.title} - ${exampleApp.name}`
      });
  
    })();

    // 卸载
    return () => {
      exampleApp.unmount();
    };
  }, []);
  
  return (
    <div ref={containerEl}></div>
  );
  
}

指定远程 Manifest 加载子应用

import React, { useEffect, useRef } from 'react';
import { createMicroApp } from '@alicloud/alfa-core';

const exampleAppManifest = 'https://somewhere/index.manifest.json'

// 主应用使用 React 实现
function HostApp(props) {
  
  const exampleApp = createMicroApp({
    // 资源描述是微应用至少需要的配置项,更多的配置项参考 API 文档
    name: 'appName',
    manifest: exampleAppManifest
  });
  
  const containerEl = useRef(null);
  
  useEffect(() => {
    // 加载
    exampleApp
      .load()
      .then((exampleApp) => {
        // 渲染
        exampleApp.mount(containerEl.current, {
          title: `${props.title} - ${exampleApp.name}`
        });
      });
    // 卸载
    return () => {
      exampleApp.unmount();
    };
  }, []);
  
  useEffect(() => {
    // 更新
    exampleApp.update({
      title: `${props.title} - ${exampleApp.name}`
    });
  }, [props.title]);
  
  return (
    <div ref={containerEl}></div>
  );  
}
1.4.33

2 months ago

1.4.32

12 months ago

1.4.24

1 year ago

1.4.23

1 year ago

1.4.25

1 year ago

1.4.30-alpha.0

1 year ago

1.4.31

1 year ago

1.4.30

1 year ago

1.4.22

1 year ago

1.4.22-alpha.0

2 years ago

1.4.20

2 years ago

1.4.19

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.4.9-alpha.2

2 years ago

1.4.14-alpha.1

2 years ago

1.4.14-alpha.0

2 years ago

1.4.10-alpha.0

2 years ago

1.4.10-alpha.1

2 years ago

1.4.10-alpha.2

2 years ago

1.4.9

2 years ago

1.4.11

2 years ago

1.4.10

2 years ago

1.4.7

2 years ago

1.4.12

2 years ago

1.4.14

2 years ago

1.4.0-alpha.8

2 years ago

1.4.0-alpha.4

2 years ago

1.4.0-alpha.5

2 years ago

1.4.0-alpha.7

2 years ago

1.4.0-alpha.0

2 years ago

1.4.0-alpha.1

2 years ago

1.4.0-alpha.2

2 years ago

1.4.0-alpha.3

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.3.1-alpha.1

2 years ago

1.3.0-beta.1

2 years ago

1.3.0-beta.2

2 years ago

1.3.0-beta.3

2 years ago

1.3.0-beta.0

2 years ago

1.3.0-canary.7

2 years ago

1.3.0-canary.5

2 years ago

1.3.0-alpha.2

2 years ago

1.3.0-alpha.3

2 years ago

1.3.0-canary.0

2 years ago

1.3.0-canary.1

2 years ago

1.3.0-alpha.1

2 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.15

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.1-next.0

3 years ago

1.0.0

3 years ago

1.0.0-next.16

3 years ago

1.0.0-next.12

3 years ago

1.0.0-next.11

3 years ago

1.0.0-next.10

3 years ago

1.0.0-next.9

3 years ago

1.0.0-next.8

3 years ago

1.0.0-next.6

3 years ago

1.0.0-next.5

3 years ago

1.0.0-next.4

3 years ago

1.0.0-next.3

3 years ago

1.0.0-next.2

3 years ago