Skip to content

Commit

Permalink
chore: readme of icestark apis (#169)
Browse files Browse the repository at this point in the history
* chore: readme

* chore: readme
  • Loading branch information
ClarkXia authored Sep 28, 2020
1 parent 435e950 commit a578edc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
81 changes: 76 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ English | [简体中文](https://ice.work/docs/icestark/about)
npm install @ice/stark --save
```

## Documentation

[https://ice.work/docs/icestark/about](https://ice.work/docs/icestark/about)

## Introduction

`icestark` is a micro frontends solution for large application, contains:
Expand All @@ -38,6 +42,7 @@ npm install @ice/stark --save

### Framework Application

#### setup in react app
```javascript
// src/App.jsx
import React from 'react';
Expand Down Expand Up @@ -88,11 +93,44 @@ ReactDOM.render(<App />, document.getElementById('ice-container'));
- `AppRoute` corresponds to the configuration of a sub-application, `path` configures all route information, `basename` configures a uniform route prefix, `url` configures assets url
- `icestark` will follow the route parsing rules like to determine the current `path`, load the static resources of the corresponding sub-application, and render

#### setup with APIs

> supported by @ice/stark@2.0.0
```javascript
import { registerMicroApps } from '@ice/stark';

regsiterMicroApps([
{
name: 'app1',
activePath: ['/', '/message', '/about'],
exact: true,
title: '通用页面',
container: document.getElementById('icestarkNode'),
url: ['//unpkg.com/icestark-child-common/build/js/index.js'],
},
{
name: 'app2',
activePath: '/seller',
title: '商家平台',
container: document.getElementById('icestarkNode'),
url: [
'//unpkg.com/icestark-child-seller/build/js/index.js',
'//unpkg.com/icestark-child-seller/build/css/index.css',
],
},
]);

start();
```

after sub-application is registered, icestark will load app according to the `activePath`.

### Sub-application

- Get the render `DOM Node` via `getMountNode`
- Trigger app mount manually via `registerAppEnter`
- Trigger app unmount manually via `registerAppLeave`
sub-application can expose lifecycles in both register lifecycles and export lifecycles ways.

#### regsiter lifecycles

```javascript
// src/index.js
Expand All @@ -117,8 +155,9 @@ if (isInIcestark()) {

```

- Get the `basename` configuration in the framework application via `getBasename`
- `renderNotFound` triggers the framework application rendering global NotFound
- Get the render `DOM Node` via `getMountNode`
- Trigger app mount manually via `registerAppEnter`
- Trigger app unmount manually via `registerAppLeave`

```javascript
// src/router.js
Expand Down Expand Up @@ -154,6 +193,38 @@ export default class App extends React.Component {
}
```

- Get the `basename` configuration in the framework application via `getBasename`
- `renderNotFound` triggers the framework application rendering global NotFound

#### exports lifecycles

exports lifecycles in sub-application:

```javascript
import ReactDOM from 'react-dom';
import App from './app';

export function mount(props) {
ReactDOM.render(<App />, document.getElementById('icestarkNode'));
}

export function unmount() {
ReactDOM.unmountComponentAtNode(document.getElementById('icestarkNode'));
}

```

sub-application should be bundled as an UMD module, add the following configuration of webpack:

```javascript
module.exports = {
output: {
library: 'sub-app-name',
libraryTarget: 'umd',
},
};
```

## Ecosystem

| Project | Version | Docs | Description |
Expand Down
2 changes: 1 addition & 1 deletion src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './util/capturedListeners';
import { AppConfig, getMicroApps, createMicroApp, unmountMicroApp, clearMicroApps } from './apps';
import { emptyAssets, recordAssets } from './util/handleAssets';
import { MOUNTED, UNMOUNTED } from './util/constant';
import { MOUNTED } from './util/constant';

export interface StartConfiguration {
shouldAssetsRemove?: (
Expand Down

0 comments on commit a578edc

Please sign in to comment.