Skip to content

Commit 2101a95

Browse files
committed
feat: align rsbuild config
1 parent f3fb9ca commit 2101a95

File tree

18 files changed

+148
-84
lines changed

18 files changed

+148
-84
lines changed

.changeset/five-ghosts-care.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/utils': patch
3+
'@modern-js/builder': patch
4+
---
5+
6+
feat: align rsbuild config
7+
feat: 对齐 rsbuild 配置

packages/cli/builder/src/shared/parseCommonConfig.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ export async function parseCommonConfig(
166166

167167
html.title ??= '';
168168

169-
html.appIcon =
170-
typeof appIcon === 'string'
171-
? { icons: [{ src: appIcon, size: 180 }] }
172-
: appIcon;
169+
html.appIcon = appIcon;
173170

174171
extraConfig.tools ??= {};
175172

packages/cli/builder/src/shared/utils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ export const isHtmlDisabled = (
119119
);
120120
};
121121

122-
const DEFAULT_WEB_BROWSERSLIST = ['> 0.01%', 'not dead', 'not op_mini all'];
122+
const DEFAULT_WEB_BROWSERSLIST = [
123+
'chrome >= 87',
124+
'edge >= 88',
125+
'firefox >= 78',
126+
'safari >= 14',
127+
];
123128

124129
const DEFAULT_BROWSERSLIST: Record<RsbuildTarget, string[]> = {
125130
web: DEFAULT_WEB_BROWSERSLIST,
126-
node: ['node >= 14'],
131+
node: ['node >= 16'],
127132
'web-worker': DEFAULT_WEB_BROWSERSLIST,
128133
};
129134

packages/cli/builder/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export type BuilderExtraConfig = {
206206
disableSvgr?: boolean;
207207
};
208208
html?: {
209-
appIcon?: string | HtmlConfig['appIcon'];
209+
appIcon?: HtmlConfig['appIcon'];
210210
// TODO: need support rsbuild favicon type in server/utils
211211
favicon?: string;
212212
};

packages/document/main-doc/docs/en/components/upgrade-browserslist.mdx

Whitespace-only changes.

packages/document/main-doc/docs/en/configure/app/html/app-icon.mdx

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type AppIconItem = {
1313
target?: 'apple-touch-icon' | 'web-app-manifest';
1414
};
1515

16-
type AppIcon = string | {
16+
type AppIcon = {
1717
name?: string;
1818
icons: AppIconItem[];
1919
filename?: string;
@@ -27,28 +27,6 @@ Set the web application icons to display when added to the home screen of a mobi
2727
- Generate the web app manifest file and its `icons` field.
2828
- Generate the `apple-touch-icon` and `manifest` tags in the HTML file.
2929

30-
### AppIcon string
31-
32-
The `appIcon` configuration of type `string` is a syntactic sugar for the `object` type.
33-
34-
```js
35-
export default {
36-
html: {
37-
appIcon: './src/assets/icon.png',
38-
},
39-
};
40-
```
41-
42-
The above configuration is equivalent to the following configuration:
43-
44-
```js
45-
export default {
46-
html: {
47-
appIcon: { icons: [{ src: './src/assets/icon.png', size: 180 }] }
48-
},
49-
};
50-
```
51-
5230
import RsbuildConfig from '@site-docs-en/components/rsbuild-config-tooltip';
5331

5432
<RsbuildConfig configName="html.appIcon" />

packages/document/main-doc/docs/en/configure/app/output/inline-scripts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type InlineScripts =
2020
};
2121
```
2222

23-
- **Default:** `false`
23+
- **Default:** `/builder-runtime([.].+)?\.js$/`
2424

2525
Whether to inline output scripts files (.js files) into HTML with `<script>` tags.
2626

packages/document/main-doc/docs/en/configure/app/output/override-browserslist.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ title: overrideBrowserslist
99

1010
```ts
1111
const defaultBrowserListMap: Record<RsbuildTarget, string[]> = {
12-
web: ['> 0.01%', 'not dead', 'not op_mini all'],
12+
web: ['chrome >= 87', 'edge >= 88', 'firefox >= 78', 'safari >= 14'],
1313
node: ['node >= 14'],
14-
'web-worker': ['> 0.01%', 'not dead', 'not op_mini all'],
14+
'web-worker': ['chrome >= 87', 'edge >= 88', 'firefox >= 78', 'safari >= 14'],
1515
};
1616
```
1717

18-
Modern.js will give priority to using the configuration in the `.browserslistrc` file in the project root directory.
18+
Specifies the range of target browsers that the project is compatible with.
1919

20-
Specifies the range of target browsers that the project is compatible with. This value will be used by [SWC](https://github.com/swc-project/swc) and [autoprefixer](https://github.com/postcss/autoprefixer) to identify the JavaScript syntax that need to be transformed and the CSS browser prefixes that need to be added.
20+
This value will be used by [SWC](https://github.com/swc-project/swc) and [autoprefixer](https://github.com/postcss/autoprefixer) to identify the JavaScript syntax that need to be transformed and the CSS browser prefixes that need to be added.
21+
22+
For other configuration methods and configuration priorities, please refer to the [Browserslist configuration](/guides/advanced-features/compatibility.html).
2123

2224
import RsbuildConfig from '@site-docs-en/components/rsbuild-config-tooltip';
2325

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
---
2-
sidebar_position: 5
2+
sidebar_position: 6
33
---
44

55
# Browser Compatibility
66

77
## Browserslist Configuration
88

9-
Modern.js supports setting the browserslist for your web applications. You can set the value of [Browserslist](https://browsersl.ist/) in the `.browserslistrc` file.
9+
Modern.js supports three ways to set the range of browsers that a web application needs to support.
1010

11-
When you create a new Modern.js project, it will includes a `.browserslistrc` configuration by default, which means that the JavaScript code will be compiled to ES6.
11+
### Method 1: Configure via `.browserslistrc` File
12+
13+
Modern.js supports setting the range of browsers that a web application needs to support. You can set the [Browserslist](https://browsersl.ist/) values in the `.browserslistrc` file.
14+
15+
When you create a new Modern.js project, a default `.browserslistrc` configuration is included, which indicates that JavaScript code will be compiled to ES6 format.
1216

1317
```yaml title=".browserslistrc"
1418
chrome >= 51
@@ -18,23 +22,63 @@ safari >= 10
1822
ios_saf >= 10
1923
```
2024

25+
When the `overrideBrowserslist` configuration is not specified in the project, this `.browserslistrc` file will take effect.
26+
27+
### Method 2: Configure via package.json
28+
29+
You can also configure browserslist by setting the `browserslist` field in the `package.json` file:
30+
31+
```json title="package.json"
32+
{
33+
"browserslist": [
34+
"chrome >= 51"
35+
// Other browser configurations...
36+
]
37+
}
38+
```
39+
40+
### Method 3: Configure via `output.overrideBrowserslist`
41+
42+
You can also configure browserslist by setting the [`output.overrideBrowserslist`](/configure/app/output/override-browserslist) field in the `modern.config.js` file:
43+
44+
```js title="modern.config.js"
45+
export default {
46+
output: {
47+
overrideBrowserslist: [
48+
'chrome >= 51',
49+
// Other browser configurations...
50+
],
51+
},
52+
};
53+
```
54+
55+
### Configuration Priority
56+
57+
The `overrideBrowserslist` configuration has a higher priority than the `.browserslistrc` file and the `browserslist` field in package.json.
58+
59+
In most scenarios, it is recommended to prioritize using the `.browserslistrc` file rather than the `overrideBrowserslist` configuration because the `.browserslistrc` file is the officially defined configuration file, has better general applicability, and can be recognized by other libraries in the community.
60+
2161
:::tip
22-
Please refer to [Rsbuild - Browserslist](https://rsbuild.rs/guide/advanced/browserslist) for more information.
62+
Please refer to [Rsbuild - Setting Browser Range](https://rsbuild.rs/zh/guide/advanced/browserslist) for more information.
2363
:::
2464

65+
import UpgradeBrowserslist from '@site-docs-en/components/upgrade-browserslist';
66+
67+
<UpgradeBrowserslist />
68+
2569
## Polyfill
2670

27-
### Polyfill At Compile
71+
### Compile-time Polyfill
2872

29-
Modern.js defaults to importing corresponding polyfill code from [core-js](https://github.com/zloirock/core-js) during compilation.
73+
Modern.js by default injects corresponding polyfill code at compile time through [core-js](https://github.com/zloirock/core-js).
3074

31-
By default, the required Polyfill code will be introduced according to the settings of the Browserslist, so there is no need to worry about the Polyfill problem of the project source code and third-party dependencies, but because it contains some Polyfill code that is not used, the final bundle size may be increased.
75+
By default, it will include the necessary polyfill code based on the project's Browserslist settings, so you generally do not need to worry about polyfill issues for your project source code and third-party dependencies. However, since some unused polyfill code is included, the final bundle size may increase.
3276

3377
:::info
34-
For case where Polyfill is not required for third-party dependencies, you can set ['output.polyfill'](/configure/app/output/polyfill) to `usage`, so that Babel compiles only Polyfill code based on the syntax used in the code.
78+
For scenarios where certain third-party dependencies clearly do not require polyfills, you can set [`output.polyfill`](/configure/app/output/polyfill) to `usage`. This way, Babel will only inject polyfill code based on the syntax used in the code during compilation.
3579

3680
:::
3781

38-
import UAPolyfill from '@site-docs-en/components/ua-polyfill';
82+
import UAPolyfill from '@site-docs/components/ua-polyfill';
3983

4084
<UAPolyfill />

packages/document/main-doc/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ See the [performance.bundleAnalyze](/configure/app/performance/bundle-analyze.ht
4646

4747
Modern.js will compile the code according to the project's Browserslist config, and inject some Polyfills. If the project does not need to be compatible with legacy browsers, you can adjust the Browserslist and drop some legacy browsers, thereby reducing the compilation overhead on syntax and polyfill.
4848

49-
Modern.js's default Browserslist config is:
49+
Modern.js's default [`output.overrideBrowserslist`](/configure/app/output/override-browserslist.html) config is:
5050

5151
```js
52-
['> 0.01%', 'not dead', 'not op_mini all'];
52+
['chrome >= 87', 'edge >= 88', 'firefox >= 78', 'safari >= 14'];
5353
```
5454

55-
For example, if you only need to be compatible with browsers above Chrome 61, you can change it to:
55+
For example, if you only need to be compatible with browsers above Chrome 100, you can change it to:
5656

5757
```js
58-
['Chrome >= 61'];
58+
['Chrome >= 100'];
5959
```
6060

6161
:::tip
62-
Please read the [Browserslist](https://rsbuild.rs/guide/advanced/browserslist) chapter to know more about the usage of Browserslist.
62+
Please read the [Browserslist configuration](/guides/advanced-features/compatibility.html) chapter to know more about the usage of Browserslist.
6363
:::
6464

6565
## Usage polyfill

0 commit comments

Comments
 (0)