Skip to content

Commit 9787dff

Browse files
authored
docs: extract document of ua polyfill to components folder (#3705)
* docs: extract document of ua polyfill to components folder * docs: add benchmark link
1 parent 663208d commit 9787dff

File tree

6 files changed

+91
-76
lines changed

6 files changed

+91
-76
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ The following solutions are available within the Modern.js ecosystem:
4040
- 🐟 [Garfish](https://github.com/web-infra-dev/garfish): A powerful micro front-end framework.
4141
- 🦆 [Reduck](https://github.com/web-infra-dev/reduck): A redux-based state management library.
4242

43+
## Benchmark
44+
45+
We use [Modern.js Benchmark](https://web-infra-dev.github.io/modern-js-benchmark/) to observe the trend of key metrics, such as bundle size, compile speed and install size.
46+
4347
## Contributing
4448

4549
> New contributors welcome!

README.zh-CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Modern.js 生态提供了以下解决方案:
4040
- 🐟 [Garfish](https://github.com/web-infra-dev/garfish): 一站式微前端解决方案。
4141
- 🦆 [Reduck](https://github.com/web-infra-dev/reduck): 基于 Redux 的状态管理库。
4242

43+
## Benchmark
44+
45+
我们通过 [Modern.js Benchmark](https://web-infra-dev.github.io/modern-js-benchmark/) 来观测核心指标的变化情况,比如 bundle size、compile speed 和 install size。
46+
4347
## 参与贡献
4448

4549
> 欢迎参与 Modern.js 贡献!
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
### Polyfill At Runtime
3+
4+
Modern.js also provides a runtime Polyfill solution based on browser [UA](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent) information, which has the following advantages over Babel:
5+
6+
- It will not be inserted into the code, reducing the code .
7+
- The same browser will share a Polyfill code. Therefore, with more and more projects, the UA-based Polyfill code will be delivered faster and faster.
8+
9+
exec `pnpm run new` to enable this features:
10+
11+
```bash
12+
? Action Enable features
13+
? Enable features Enable UA-based Polyfill Feature
14+
```
15+
16+
After executing the command, register the Polyfill plugin in `modern.config.ts`:
17+
18+
```ts title="modern.config.ts"
19+
import polyfillPlugin from '@modern-js/plugin-polyfill';
20+
21+
export default defineConfig({
22+
plugins: [..., polyfillPlugin()],
23+
});
24+
```
25+
26+
After configuring `output.polyfill` as `ua` and executing `pnpm run build & & pnpm run serve` to start the server, visiting the page can see that the HTML product contains the following script:
27+
28+
```js
29+
<script src="/__polyfill__" crossorigin></script>
30+
```
31+
32+
Visit the page `http://localhost:8080/__polyfill__` on Chrome 51 to see:
33+
34+
![ua-polyfill](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/ua-polyfill.png)
35+
36+
:::caution
37+
This feature only works when using Modern.js built-in Web Server.
38+
39+
If you need to customize the HTML template, please refer to [HTML Template](/guides/basic-features/html.html). Manually modifying the template through html.template / tools.html will cause this feature not work.
40+
:::

packages/document/main-doc/docs/en/guides/advanced-features/compatibility.mdx

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,6 @@ For case where Polyfill is not required for third-party dependencies, you can se
5656

5757
:::
5858

59-
### Polyfill At Runtime
59+
import UAPolyfill from '@site-docs-en/components/ua-polyfill';
6060

61-
Modern.js also provides a runtime Polyfill solution based on browser [UA](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent) information, which has the following advantages over Babel:
62-
63-
- It will not be inserted into the code, reducing the code .
64-
- The same browser will share a Polyfill code. Therefore, with more and more projects, the UA-based Polyfill code will be delivered faster and faster.
65-
66-
exec `pnpm run new` to enable this features:
67-
68-
```bash
69-
? Action Enable features
70-
? Enable features Enable UA-based Polyfill Feature
71-
```
72-
73-
After executing the command, register the Polyfill plugin in `modern.config.ts`:
74-
75-
```ts title="modern.config.ts"
76-
import polyfillPlugin from '@modern-js/plugin-polyfill';
77-
78-
export default defineConfig({
79-
plugins: [..., polyfillPlugin()],
80-
});
81-
```
82-
83-
After configuring `output.polyfill` as `ua` and executing `pnpm run build & & pnpm run serve` to start the server, visiting the page can see that the HTML product contains the following script:
84-
85-
```js
86-
<script src="/__polyfill__" crossorigin></script>
87-
```
88-
89-
Visit the page `http://localhost:8080/__polyfill__` on Chrome 51 to see:
90-
91-
![ua-polyfill](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/ua-polyfill.png)
92-
93-
:::caution
94-
This feature only works when using Modern.js built-in Web Server.
95-
96-
If you need to customize the HTML template, please refer to [HTML Template](/guides/basic-features/html.html). Manually modifying the template through html.template / tools.html will cause this feature not work.
97-
:::
61+
<UAPolyfill />
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### 运行时按需 Polyfill
2+
3+
Modern.js 中还提供了基于浏览器 [UA](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent) 信息的运行时按需 Polyfill 方案,相比于 Babel 优势如下:
4+
5+
- 不会插入到代码中,只根据访问页面的设备,按需下发 Polyfill 代码 ,减少整体代码体积。
6+
- 相同浏览器会公用一份 Polyfill 代码。因此,随着项目越来越多,基于 UA 的 Polyfill 代码下发速度会越来越快,综合速度超过常规方案。
7+
8+
可以通过微生成器开启该功能:
9+
10+
```bash
11+
? 请选择你想要的操作 启用可选功能
12+
? 启用可选功能 启用「基于 UA 的 Polyfill」功能
13+
```
14+
15+
执行命令后,在 `modern.config.ts` 中注册 Polyfill 插件:
16+
17+
```ts title="modern.config.ts"
18+
import polyfillPlugin from '@modern-js/plugin-polyfill';
19+
20+
export default defineConfig({
21+
plugins: [..., polyfillPlugin()],
22+
});
23+
```
24+
25+
配置 `output.polyfill``ua` 并且执行 `pnpm run build && pnpm run serve` 启动服务器后,访问页面可以看到 HTML 产物中包含如下脚本:
26+
27+
```js
28+
<script src="/__polyfill__" crossorigin></script>
29+
```
30+
31+
在 Chrome 51 下访问页面可以看到 `http://localhost:8080/__polyfill__` 返回内容如下:
32+
33+
![ua-polyfill](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/ua-polyfill.png)
34+
35+
:::caution 注意
36+
该功能只有在使用 Modern.js 内置的 Web Server 时才会生效。
37+
38+
如果有自定义模版的需求,请参考 [HTML 模板](/guides/basic-features/html.html)。通过 `html.template``tools.html` 手动修改模版时,可能会导致该功能无法正确生效。
39+
:::

packages/document/main-doc/docs/zh/guides/advanced-features/compatibility.mdx

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,6 @@ Modern.js 在编译时默认通过 [core-js](https://github.com/zloirock/core-js
3535

3636
:::
3737

38-
### 运行时按需 Polyfill
38+
import UAPolyfill from '@site-docs/components/ua-polyfill';
3939

40-
Modern.js 中还提供了基于浏览器 [UA](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent) 信息的运行时按需 Polyfill 方案,相比于 Babel 优势如下:
41-
42-
- 不会插入到代码中,只根据访问页面的设备,按需下发 Polyfill 代码 ,减少整体代码体积。
43-
- 相同浏览器会公用一份 Polyfill 代码。因此,随着项目越来越多,基于 UA 的 Polyfill 代码下发速度会越来越快,综合速度超过常规方案。
44-
45-
可以通过微生成器开启该功能:
46-
47-
```bash
48-
? 请选择你想要的操作 启用可选功能
49-
? 启用可选功能 启用「基于 UA 的 Polyfill」功能
50-
```
51-
52-
执行命令后,在 `modern.config.ts` 中注册 Polyfill 插件:
53-
54-
```ts title="modern.config.ts"
55-
import polyfillPlugin from '@modern-js/plugin-polyfill';
56-
57-
export default defineConfig({
58-
plugins: [..., polyfillPlugin()],
59-
});
60-
```
61-
62-
配置 `output.polyfill``ua` 并且执行 `pnpm run build && pnpm run serve` 启动服务器后,访问页面可以看到 HTML 产物中包含如下脚本:
63-
64-
```js
65-
<script src="/__polyfill__" crossorigin></script>
66-
```
67-
68-
在 Chrome 51 下访问页面可以看到 `http://localhost:8080/__polyfill__` 返回内容如下:
69-
70-
![ua-polyfill](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/ua-polyfill.png)
71-
72-
:::caution 注意
73-
该功能只有在使用 Modern.js 内置的 Web Server 时才会生效。
74-
75-
如果有自定义模版的需求,请参考 [HTML 模板](/guides/basic-features/html.html)。通过 `html.template``tools.html` 手动修改模版时,可能会导致该功能无法正确生效。
76-
:::
40+
<UAPolyfill />

0 commit comments

Comments
 (0)