kj-micro-app 1.0.2
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/LICENSE +21 -0
- package/README.md +156 -0
- package/README.zh-cn.md +156 -0
- package/lib/index.d.ts +483 -0
- package/lib/index.esm.js +9419 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.min.js +2 -0
- package/lib/index.min.js.map +1 -0
- package/lib/index.umd.js +2 -0
- package/lib/index.umd.js.map +1 -0
- package/package.json +134 -0
- package/polyfill/jsx-custom-event.js +54 -0
- package/polyfill/jsx-custom-event.js.map +1 -0
- package/typings/global.d.ts +582 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 JD.com, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://jd-opensource.github.io/micro-app/">
|
|
3
|
+
<img src="https://jd-opensource.github.io/micro-app/home/assets/logo.png" alt="logo" width="200"/>
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@micro-zoe/micro-app">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@micro-zoe/micro-app.svg" alt="version"/>
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@micro-zoe/micro-app">
|
|
12
|
+
<img src="https://img.shields.io/npm/dt/@micro-zoe/micro-app.svg" alt="downloads"/>
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/jd-opensource/micro-app/blob/master/LICENSE">
|
|
15
|
+
<img src="https://img.shields.io/npm/l/@micro-zoe/micro-app.svg" alt="license"/>
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/jd-opensource/micro-app/blob/dev/Contact.md">
|
|
18
|
+
<img src="https://img.shields.io/badge/chat-wechat-blue" alt="WeChat">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://travis-ci.com/github/jd-opensource/micro-app">
|
|
21
|
+
<img src="https://api.travis-ci.com/jd-opensource/micro-app.svg?branch=master" alt="travis"/>
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://coveralls.io/github/jd-opensource/micro-app?branch=master">
|
|
24
|
+
<img src="https://coveralls.io/repos/github/jd-opensource/micro-app/badge.svg?branch=master" alt="coveralls"/>
|
|
25
|
+
</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
English|[简体中文](./README.zh-cn.md)|[Documentation](https://jd-opensource.github.io/micro-app/)|[Discussions](https://github.com/jd-opensource/micro-app/discussions)|[WeChat](./Contact.md)
|
|
29
|
+
|
|
30
|
+
# 📖Introduction
|
|
31
|
+
micro-app is a micro front-end framework launched by JD Retail. It renders based on webcomponent-like and realizes the micro front-end from component thinking, it aiming to reduce the difficulty of getting started and improve work efficiency.
|
|
32
|
+
|
|
33
|
+
It is the lowest cost framework for accessing micro front-end, and provides a series of perfect functions such as JS sandbox, style isolation, element isolation, preloading, resource address completion, plugin system, data communication and so on.
|
|
34
|
+
|
|
35
|
+
micro-app has no restrictions on the front-end framework, and any framework can be used as a base application to embed any type of micro application of the framework.
|
|
36
|
+
|
|
37
|
+
# How to use
|
|
38
|
+
## Base application
|
|
39
|
+
**1、Install**
|
|
40
|
+
```bash
|
|
41
|
+
yarn add @micro-zoe/micro-app
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**2、import at the entrance**
|
|
45
|
+
```js
|
|
46
|
+
// main.js
|
|
47
|
+
import microApp from '@micro-zoe/micro-app'
|
|
48
|
+
|
|
49
|
+
microApp.start()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**3、Use components in page**
|
|
53
|
+
```html
|
|
54
|
+
<!-- my-page.vue -->
|
|
55
|
+
<template>
|
|
56
|
+
<!-- 👇 name is the app name, url is the app address -->
|
|
57
|
+
<micro-app name='my-app' url='http://localhost:3000/'></micro-app>
|
|
58
|
+
</template>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Sub application
|
|
62
|
+
**Set cross-domain support in the headers of webpack-dev-server**
|
|
63
|
+
```js
|
|
64
|
+
devServer: {
|
|
65
|
+
headers: {
|
|
66
|
+
'Access-Control-Allow-Origin': '*',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The above micro front-end rendering is completed, and the effect is as follows:
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
More detailed configuration can be viewed [Documentation](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/start).
|
|
76
|
+
|
|
77
|
+
# 🤝 Contribution
|
|
78
|
+
If you're interested in this project, you're welcome to mention pull request, and also welcome your "Star" ^_^
|
|
79
|
+
|
|
80
|
+
### development
|
|
81
|
+
1、Clone
|
|
82
|
+
```
|
|
83
|
+
git clone https://github.com/jd-opensource/micro-app.git
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
2、Install dependencies
|
|
87
|
+
```
|
|
88
|
+
yarn bootstrap
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
3、Run project
|
|
92
|
+
```
|
|
93
|
+
yarn start
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
For more commands, see [DEVELOP](https://github.com/jd-opensource/micro-app/blob/master/DEVELOP.md)
|
|
97
|
+
|
|
98
|
+
# FAQ
|
|
99
|
+
<details>
|
|
100
|
+
|
|
101
|
+
<summary>What are the advantages of micro-app?</summary>
|
|
102
|
+
It is easy to use and low invasive. It only needs to change a small amount of code to access the micro front-end, and provides rich functions at the same time.
|
|
103
|
+
|
|
104
|
+
</details>
|
|
105
|
+
<details>
|
|
106
|
+
<summary>How compatible?</summary>
|
|
107
|
+
The micro-app relies on two newer APIs, CustomElements and Proxy.
|
|
108
|
+
|
|
109
|
+
For browsers that do not support CustomElements, they can be compatible by introducing polyfills. For details, please refer to: [webcomponents/polyfills](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)。
|
|
110
|
+
|
|
111
|
+
However, Proxy is not compatible for the time being, so the micro-app cannot be run on browsers that do not support Proxy.
|
|
112
|
+
|
|
113
|
+
Browser compatibility can be viewed: [Can I Use](https://caniuse.com/?search=Proxy)
|
|
114
|
+
|
|
115
|
+
The general is as follows:
|
|
116
|
+
- desktop: Except IE browser, other browsers are basically compatible.
|
|
117
|
+
- mobile: ios10+、android5+
|
|
118
|
+
</details>
|
|
119
|
+
|
|
120
|
+
<details>
|
|
121
|
+
<summary>Must micro applications support cross-domain?</summary>
|
|
122
|
+
yes!
|
|
123
|
+
|
|
124
|
+
If it is a development environment, you can set headers in webpack-dev-server to support cross-domain.
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
devServer: {
|
|
128
|
+
headers: {
|
|
129
|
+
'Access-Control-Allow-Origin': '*',
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
If it is a production environment, you can support cross-domain through [Configuration nginx](https://segmentfault.com/a/1190000012550346).
|
|
135
|
+
|
|
136
|
+
</details>
|
|
137
|
+
|
|
138
|
+
<details>
|
|
139
|
+
<summary>Does it support vite?</summary>
|
|
140
|
+
|
|
141
|
+
Yes, please see [adapt vite](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/framework/vite) for details.
|
|
142
|
+
</details>
|
|
143
|
+
|
|
144
|
+
<details>
|
|
145
|
+
<summary>Does it support ssr?</summary>
|
|
146
|
+
|
|
147
|
+
Yes, please see [nextjs](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/framework/nextjs), [nuxtjs](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/framework/nuxtjs) for details.
|
|
148
|
+
</details>
|
|
149
|
+
|
|
150
|
+
# Contributors
|
|
151
|
+
<a href="https://github.com/jd-opensource/micro-app/graphs/contributors">
|
|
152
|
+
<img src="https://contrib.rocks/image?repo=jd-opensource/micro-app" />
|
|
153
|
+
</a>
|
|
154
|
+
|
|
155
|
+
# License
|
|
156
|
+
[MIT License](https://github.com/jd-opensource/micro-app/blob/master/LICENSE)
|
package/README.zh-cn.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://jd-opensource.github.io/micro-app/">
|
|
3
|
+
<img src="https://zeroing.jd.com/micro-app/media/logo.png" alt="logo" width="200"/>
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@micro-zoe/micro-app">
|
|
9
|
+
<img src="https://img.shields.io/npm/v/@micro-zoe/micro-app.svg" alt="version"/>
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@micro-zoe/micro-app">
|
|
12
|
+
<img src="https://img.shields.io/npm/dt/@micro-zoe/micro-app.svg" alt="downloads"/>
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/jd-opensource/micro-app/blob/master/LICENSE">
|
|
15
|
+
<img src="https://img.shields.io/npm/l/@micro-zoe/micro-app.svg" alt="license"/>
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/jd-opensource/micro-app/blob/dev/Contact.md">
|
|
18
|
+
<img src="https://img.shields.io/badge/chat-wechat-blue" alt="WeChat">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://travis-ci.com/github/jd-opensource/micro-app">
|
|
21
|
+
<img src="https://api.travis-ci.com/jd-opensource/micro-app.svg?branch=master" alt="travis"/>
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://coveralls.io/github/jd-opensource/micro-app?branch=master">
|
|
24
|
+
<img src="https://coveralls.io/repos/github/jd-opensource/micro-app/badge.svg?branch=master" alt="coveralls"/>
|
|
25
|
+
</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
[English](https://github.com/jd-opensource/micro-app)|简体中文|[官网文档](https://jd-opensource.github.io/micro-app/)|[讨论组](https://github.com/jd-opensource/micro-app/discussions)|[微信群](./Contact.md)
|
|
29
|
+
|
|
30
|
+
# 📖简介
|
|
31
|
+
micro-app是京东零售推出的一款微前端框架,它基于类WebComponent进行渲染,从组件化的思维实现微前端,旨在降低上手难度、提升工作效率。它是目前接入微前端成本最低的框架,并且提供了JS沙箱、样式隔离、元素隔离、预加载、虚拟路由系统、插件系统、数据通信等一系列完善的功能。
|
|
32
|
+
|
|
33
|
+
micro-app与技术栈无关,对前端框架没有限制,任何框架都可以作为基座应用嵌入任何类型的子应用。
|
|
34
|
+
|
|
35
|
+
# 如何使用
|
|
36
|
+
## 主应用
|
|
37
|
+
|
|
38
|
+
**1、安装依赖**
|
|
39
|
+
```bash
|
|
40
|
+
yarn add @micro-zoe/micro-app
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**2、在入口文件引入**
|
|
44
|
+
```js
|
|
45
|
+
// main.js
|
|
46
|
+
import microApp from '@micro-zoe/micro-app'
|
|
47
|
+
|
|
48
|
+
microApp.start()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**3、在页面中嵌入微前端应用**
|
|
52
|
+
```html
|
|
53
|
+
<!-- 👇 name为应用名称,url为应用地址 -->
|
|
54
|
+
<micro-app name='my-app' url='http://localhost:3000/'></micro-app>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 子应用
|
|
58
|
+
|
|
59
|
+
**在webpack-dev-server的headers中设置跨域支持。**
|
|
60
|
+
```js
|
|
61
|
+
devServer: {
|
|
62
|
+
headers: {
|
|
63
|
+
'Access-Control-Allow-Origin': '*',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
以上即完成微前端的嵌入,效果如下:
|
|
69
|
+
|
|
70
|
+
<img src="https://img12.360buyimg.com/imagetools/jfs/t1/196940/34/1541/38365/610a14fcE46c21374/c321b9f8fa50a8fc.png" alt="result" width='900'/>
|
|
71
|
+
|
|
72
|
+
更多详细配置可以查看[官网文档](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/start)
|
|
73
|
+
|
|
74
|
+
# 🤝 参与共建
|
|
75
|
+
如果您对这个项目感兴趣,欢迎参与贡献,也欢迎 "Star" 支持一下 ^_^
|
|
76
|
+
|
|
77
|
+
### 本地运行
|
|
78
|
+
1、克隆项目
|
|
79
|
+
```
|
|
80
|
+
git clone https://github.com/jd-opensource/micro-app.git
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
2、安装依赖
|
|
84
|
+
```
|
|
85
|
+
yarn bootstrap
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
3、运行项目
|
|
89
|
+
```
|
|
90
|
+
yarn start # 访问 http://localhost:3000
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
更多命令请查看[DEVELP](https://github.com/jd-opensource/micro-app/blob/master/DEVELOP.zh-cn.md)
|
|
94
|
+
|
|
95
|
+
# FAQ
|
|
96
|
+
[问题汇总](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/questions)
|
|
97
|
+
<details>
|
|
98
|
+
|
|
99
|
+
<summary>micro-app的优势在哪里?</summary>
|
|
100
|
+
上手简单、侵入性低,只需改动少量的代码即可接入微前端,同时提供丰富的功能。
|
|
101
|
+
|
|
102
|
+
具体细节请参考文章:[micro-app介绍](https://github.com/jd-opensource/micro-app/issues/8)
|
|
103
|
+
|
|
104
|
+
</details>
|
|
105
|
+
<details>
|
|
106
|
+
<summary>兼容性如何?</summary>
|
|
107
|
+
micro-app依赖于CustomElements和Proxy两个较新的API。
|
|
108
|
+
|
|
109
|
+
对于不支持CustomElements的浏览器,可以通过引入polyfill进行兼容,详情可参考:[webcomponents/polyfills](https://github.com/webcomponents/polyfills/tree/master/packages/custom-elements)。
|
|
110
|
+
|
|
111
|
+
但是Proxy暂时没有做兼容,所以对于不支持Proxy的浏览器无法运行micro-app。
|
|
112
|
+
|
|
113
|
+
浏览器兼容性可以查看:[Can I Use](https://caniuse.com/?search=Proxy)
|
|
114
|
+
|
|
115
|
+
总体如下:
|
|
116
|
+
- PC端:除了IE浏览器,其它浏览器基本兼容。
|
|
117
|
+
- 移动端:ios10+、android5+
|
|
118
|
+
</details>
|
|
119
|
+
|
|
120
|
+
<details>
|
|
121
|
+
<summary>子应用一定要支持跨域吗?</summary>
|
|
122
|
+
是的!
|
|
123
|
+
|
|
124
|
+
如果是开发环境,可以在webpack-dev-server中设置headers支持跨域。
|
|
125
|
+
```js
|
|
126
|
+
devServer: {
|
|
127
|
+
headers: {
|
|
128
|
+
'Access-Control-Allow-Origin': '*',
|
|
129
|
+
},
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
如果是线上环境,可以通过[配置nginx](https://segmentfault.com/a/1190000012550346)支持跨域。
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
<details>
|
|
137
|
+
<summary>支持vite吗?</summary>
|
|
138
|
+
|
|
139
|
+
支持,详情请查看[适配vite](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/framework/vite)
|
|
140
|
+
</details>
|
|
141
|
+
|
|
142
|
+
<details>
|
|
143
|
+
<summary>支持ssr吗?</summary>
|
|
144
|
+
|
|
145
|
+
支持,详情请查看[nextjs](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/framework/nextjs)、[nuxtjs](https://jd-opensource.github.io/micro-app/docs.html#/zh-cn/framework/nuxtjs)
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# 贡献者们
|
|
150
|
+
<a href="https://github.com/jd-opensource/micro-app/graphs/contributors">
|
|
151
|
+
<img src="https://contrib.rocks/image?repo=jd-opensource/micro-app" />
|
|
152
|
+
</a>
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# License
|
|
156
|
+
[MIT License](https://github.com/jd-opensource/micro-app/blob/master/LICENSE)
|