Skip to content

Commit 906bd94

Browse files
authored
feat(mwa-generator): add a default browserslist config for new projects (#3695)
1 parent 958f2f9 commit 906bd94

File tree

6 files changed

+127
-74
lines changed

6 files changed

+127
-74
lines changed

.changeset/old-swans-switch.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/mwa-generator': patch
3+
---
4+
5+
feat(mwa-generator): add a default browserslist config for new projects
6+
7+
feat(mwa-generator): 为新项目增加默认的 browserslist 配置

packages/document/builder-doc/docs/en/guide/advanced/browserslist.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Set via `browserslist` in `package.json`:
3838

3939
Set via a separate `.browserslistrc` file:
4040

41-
```
41+
```yaml
4242
iOS >= 9
4343
Android >= 4.4
4444
last 2 versions
@@ -101,11 +101,45 @@ In most cases, it is recommended to use the `.browserslistrc` file rather than t
101101

102102
The following are some commonly used Browserslist, you can choose according to your project type.
103103

104-
### Mobile H5 scene
104+
### Desktop PC scenario
105+
106+
In the desktop PC scenario, if you need to be compatible with IE 11 browsers, you can set Browserslist to:
107+
108+
```yaml
109+
> 0.5%
110+
not dead
111+
Internet Explorer 11
112+
```
113+
114+
The above Browserslist will compile the code to the ES5 specification. For the specific browser list, please check [browserslist.dev](https://browserslist.dev/?q=PiAwLjUlLCBub3QgZGVhZCwgSUUgMTE%3D).
115+
116+
If you don't need to be compatible with IE 11 browsers, you can adjust Browserslist to get a more performant output, such as:
105117

106-
The mobile H5 scene is mainly compatible with `iOS` and `Android` systems, usually we set Browserslist as:
118+
- Set to browsers that supports native ES Modules (recommended):
107119

120+
```yaml
121+
chrome >= 61
122+
edge >= 16
123+
firefox >= 60
124+
safari >= 11
125+
ios_saf >= 11
108126
```
127+
128+
- Set to browsers that support ES6:
129+
130+
```yaml
131+
chrome >= 51
132+
edge >= 15
133+
firefox >= 54
134+
safari >= 10
135+
ios_saf >= 10
136+
```
137+
138+
### Mobile H5 scenario
139+
140+
The mobile H5 scenario is mainly compatible with `iOS` and `Android` systems, usually we set Browserslist as:
141+
142+
```yaml
109143
iOS >= 9
110144
Android >= 4.4
111145
last 2 versions
@@ -119,36 +153,14 @@ The above Browserslist will compile the code to the ES5 specification, which is
119153

120154
You can also choose to use the ES6 specification in the H5 scene, which will make the performance of the page better. The corresponding Browserslist is as follows:
121155

122-
```
156+
```yaml
123157
iOS >= 10
124158
Chrome >= 51
125159
> 0.5%
126160
not dead
127161
not op_mini all
128162
```
129163

130-
### Desktop PC scene
131-
132-
In the desktop PC scenario, if you need to be compatible with IE 11 browsers, you can set Browserslist to:
133-
134-
```
135-
> 0.5%
136-
not dead
137-
Internet Explorer 11
138-
```
139-
140-
The above Browserslist will compile the code to the ES5 specification. For the specific browser list, please check [browserslist.dev](https://browserslist.dev/?q=PiAwLjUlLCBub3QgZGVhZCwgSUUgMTE%3D).
141-
142-
If you don't need to be compatible with IE 11 browsers, you can adjust Browserslist to get a more performant output, such as setting it to browsers that supports native ES Modules:
143-
144-
```
145-
chrome >= 61
146-
edge >= 16
147-
firefox >= 60
148-
safari >= 11
149-
ios_saf >= 11
150-
```
151-
152164
## Default Browserslist
153165

154166
Builder will set different default values of Browserslist according to [build target](/guide/basic/build-target.html), but we recommend that you explicitly set Browserslist in your project, which will make the compatible scope of the project more clear.
@@ -157,7 +169,7 @@ Builder will set different default values of Browserslist according to [build ta
157169

158170
The default values of web target are as follows:
159171

160-
```bash
172+
```yaml
161173
> 0.01%
162174
not dead
163175
not op_mini all
@@ -169,15 +181,15 @@ Under this browser range, JavaScript code will be compiled to ES5 syntax.
169181

170182
Node target will be compatible with Node.js 14.0 by default.
171183

172-
```bash
184+
```yaml
173185
node >= 14
174186
```
175187

176188
### Web Worker Target
177189

178190
The default Browserslist of the Web Worker target is consistent with the Web target.
179191

180-
```bash
192+
```yaml
181193
> 0.01%
182194
not dead
183195
not op_mini all
@@ -187,7 +199,7 @@ not op_mini all
187199

188200
Modern Web target will be compatible with browsers that support [native ES Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) by default.
189201

190-
```bash
202+
```yaml
191203
chrome >= 61
192204
edge >= 16
193205
firefox >= 60

packages/document/builder-doc/docs/zh/guide/advanced/browserslist.md

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ polyfill 是一种用于解决浏览器兼容问题的技术。它用于模拟
3838

3939
通过独立的 `.browserslistrc` 文件设置:
4040

41-
```
41+
```yaml
4242
iOS >= 9
4343
Android >= 4.4
4444
last 2 versions
@@ -101,11 +101,45 @@ export default {
101101

102102
以下是一些常用的浏览器范围,你可以根据自己的项目类型进行选择。
103103

104+
### 桌面端 PC 场景
105+
106+
在桌面端 PC 场景下,如果你需要兼容 IE 11 浏览器,则可以将 Browserslist 设置为:
107+
108+
```yaml
109+
> 0.5%
110+
not dead
111+
IE 11
112+
```
113+
114+
以上浏览器范围会将代码编译至 ES5 规范,具体对应的浏览器列表可以查看 [browserslist.dev](https://browserslist.dev/?q=PiAwLjUlLCBub3QgZGVhZCwgSUUgMTE%3D)
115+
116+
如果你不需要兼容 IE 11 浏览器,那么可以调整 Browserslist 来获得更高性能的产物,比如:
117+
118+
- 设置为支持原生 ES Modules 的浏览器(推荐):
119+
120+
```yaml
121+
chrome >= 61
122+
edge >= 16
123+
firefox >= 60
124+
safari >= 11
125+
ios_saf >= 11
126+
```
127+
128+
- 设置为支持 ES6 的浏览器:
129+
130+
```yaml
131+
chrome >= 51
132+
edge >= 15
133+
firefox >= 54
134+
safari >= 10
135+
ios_saf >= 10
136+
```
137+
104138
### 移动端 H5 场景
105139

106140
移动端 H5 场景主要兼容 `iOS``Android` 系统,通常我们将 Browserslist 设置为:
107141

108-
```
142+
```yaml
109143
iOS >= 9
110144
Android >= 4.4
111145
last 2 versions
@@ -119,36 +153,14 @@ not dead
119153

120154
你也可以选择在 H5 场景使用 ES6 规范,这样会让页面的性能表现更好,对应的 Browserslist 如下:
121155

122-
```
156+
```yaml
123157
iOS >= 10
124158
Chrome >= 51
125159
> 0.5%
126160
not dead
127161
not op_mini all
128162
```
129163

130-
### 桌面端 PC 场景
131-
132-
在桌面端 PC 场景下,如果你需要兼容 IE 11 浏览器,则可以将 Browserslist 设置为:
133-
134-
```
135-
> 0.5%
136-
not dead
137-
IE 11
138-
```
139-
140-
以上浏览器范围会将代码编译至 ES5 规范,具体对应的浏览器列表可以查看 [browserslist.dev](https://browserslist.dev/?q=PiAwLjUlLCBub3QgZGVhZCwgSUUgMTE%3D)
141-
142-
如果你不需要兼容 IE 11 浏览器,那么可以调整 Browserslist 来获得更高性能的产物,比如设置为支持原生 ES Modules 的浏览器:
143-
144-
```
145-
chrome >= 61
146-
edge >= 16
147-
firefox >= 60
148-
safari >= 11
149-
ios_saf >= 11
150-
```
151-
152164
## Browserslist 默认值
153165

154166
Builder 会根据[构建产物类型](/guide/basic/build-target.html)来设置不同的 Browserslist 默认值,但我们推荐你在项目中显式设置 Browserslist,这会让项目的兼容范围更加明确。
@@ -157,7 +169,7 @@ Builder 会根据[构建产物类型](/guide/basic/build-target.html)来设置
157169

158170
Web 产物的默认值如下所示:
159171

160-
```
172+
```yaml
161173
> 0.01%
162174
not dead
163175
not op_mini all
@@ -169,15 +181,15 @@ not op_mini all
169181

170182
Node 产物默认最低兼容到 Node.js 14.0 版本。
171183

172-
```
184+
```yaml
173185
node >= 14
174186
```
175187

176188
### Web Worker 产物
177189

178190
Web Worker 产物默认的浏览器范围与 Web 一致。
179191

180-
```
192+
```yaml
181193
> 0.01%
182194
not dead
183195
not op_mini all
@@ -187,7 +199,7 @@ not op_mini all
187199

188200
Modern Web 产物默认最低兼容到支持[原生 ES Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) 的浏览器。
189201

190-
```
202+
```yaml
191203
chrome >= 61
192204
edge >= 16
193205
firefox >= 60

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
---
2-
title: Compatibility
32
sidebar_position: 5
43
---
5-
# Compatibility
4+
5+
# Browser Compatibility
6+
7+
## Browserslist Configuration
8+
9+
Modern.js supports setting the browserslist for your web applications. You can set the [Browserslist](https://browsersl.ist/) in the `.browserslistrc` file.
10+
11+
When you create a new Modern.js project, it includes a `.browserslistrc` configuration by default, which means that JavaScript code will be compiled to ES6.
12+
13+
```yaml title=".browserslistrc"
14+
chrome >= 51
15+
edge >= 15
16+
firefox >= 54
17+
safari >= 10
18+
ios_saf >= 10
19+
```
20+
21+
:::tip
22+
Please refer to [Modern.js Builder - Browserslist](https://modernjs.dev/builder/en/guide/advanced/browserslist) for more information.
23+
:::
624

725
## Browserslist
826

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
---
2-
title: 客户端兼容性
32
sidebar_position: 5
43
---
5-
# 客户端兼容性
4+
5+
# 浏览器兼容性
66

77
## Browserslist 配置
88

9-
Modern.js 支持在项目根目录 `package.json` 文件中的 `browserslist` 字段(或单独的 `.browserslistrc` 文件)指定项目覆盖的目标浏览器范围。该值会被 [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env)[`autoprefixer`](https://github.com/postcss/autoprefixer) 用来确定需要转换的 JavaScript 语法特性和需要添加的 CSS 浏览器前缀
9+
Modern.js 支持设置 Web 应用需要兼容的浏览器范围,你可以在 `.browserslistrc` 文件里设置 [Browserslist](https://browsersl.ist/) 的值
1010

11-
Modern.js 中默认值如下:
11+
当你创建一个新的 Modern.js 项目时,默认会包含一份 `.browserslistrc` 配置,这表示 JavaScript 代码会被编译至 ES6 格式。
1212

13-
```js
14-
['> 0.01%', 'not dead', 'not op_mini all'];
13+
```yaml title=".browserslistrc"
14+
chrome >= 51
15+
edge >= 15
16+
firefox >= 54
17+
safari >= 10
18+
ios_saf >= 10
1519
```
1620

17-
可以在[这里](https://github.com/browserslist/browserslist)了解如何自定义浏览器范围。
18-
19-
查看 Modern.js Builder 文档了解更多 [Browserslist](https://modernjs.dev/builder/guide/advanced/browserslist.html) 相关内容。
20-
21-
:::note
22-
Modern.js 支持配置 [output.overrideBrowserslist](/configure/app/output/override-browserslist) 覆盖默认 browserslist 值。
23-
21+
:::tip
22+
请查看 [Modern.js Builder - 设置浏览器范围](https://modernjs.dev/builder/guide/advanced/browserslist) 来了解更多内容。
2423
:::
2524

2625
## Polyfill
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
chrome >= 51
2+
edge >= 15
3+
firefox >= 54
4+
safari >= 10
5+
ios_saf >= 10

0 commit comments

Comments
 (0)