Skip to main content

支持的浏览器和特性

支持的浏览器

¥Supported Browsers

默认情况下,生成的项目支持所有现代浏览器。对 Internet Explorer 9、10 和 11 的支持需要 polyfill。对于一组支持旧浏览器的 polyfill,请使用 react-app-polyfill

¥By default, the generated project supports all modern browsers. Support for Internet Explorer 9, 10, and 11 requires polyfills. For a set of polyfills to support older browsers, use react-app-polyfill.

支持的语言特性

¥Supported Language Features

该项目支持最新 JavaScript 标准的超集。除了 ES6 语法特性外,它还支持:

¥This project supports a superset of the latest JavaScript standard. In addition to ES6 syntax features, it also supports:

了解有关 不同的提案阶段 的更多信息。

¥Learn more about different proposal stages.

虽然我们建议谨慎使用实验性提案,但 Facebook 在产品代码中大量使用了这些功能,因此如果这些提案中的任何一个在未来发生变化,我们打算提供 codemods

¥While we recommend using experimental proposals with some caution, Facebook heavily uses these features in the product code, so we intend to provide codemods if any of these proposals change in the future.

请注意,该项目默认不包含 polyfills

¥Note that this project includes no polyfills by default.

如果你使用任何其他需要运行时支持的 ES6+ 功能(例如 Array.from()Symbol),请确保你是 手动包含适当的 polyfill,或者你的目标浏览器已经支持它们。

¥If you use any other ES6+ features that need runtime support (such as Array.from() or Symbol), make sure you are including the appropriate polyfills manually, or that the browsers you are targeting already support them.

配置支持的浏览器

¥Configuring Supported Browsers

默认情况下,生成的项目在 package.json 文件中包含一个 browserslist 配置,以基于全局使用 (> 0.2%) 的广泛浏览器用于生产构建,以及现代浏览器用于开发。这提供了良好的开发体验,尤其是在使用 async/await 等语言功能时,但仍提供与生产中许多浏览器的高度兼容性。

¥By default, the generated project includes a browserslist configuration in your package.json file to target a broad range of browsers based on global usage (> 0.2%) for production builds, and modern browsers for development. This gives a good development experience, especially when using language features such as async/await, but still provides high compatibility with many browsers in production.

browserslist 配置控制输出的 JavaScript,以便触发的代码与指定的浏览器兼容。production 列表将在通过运行 build 脚本创建生产版本时使用,而 development 列表将在运行 start 脚本时使用。你可以使用 [https://browserl.ist](https://browserl.ist) 查看你配置的 browserslist 支持的浏览器。

¥The browserslist configuration controls the outputted JavaScript so that the emitted code will be compatible with the browsers specified. The production list will be used when creating a production build by running the build script, and the development list will be used when running the start script. You can use https://browserl.ist to see the browsers supported by your configured browserslist.

这是在 package.json 中指定的示例 browserslist

¥Here is an example browserslist that is specified in package.json:

"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}

请注意,这不会自动为你包含 polyfill。根据你支持的浏览器,你仍然需要根据需要填充语言功能(见上文)。

¥Note that this does not include polyfills automatically for you. You will still need to polyfill language features (see above) as needed based on the browsers you are supporting.

编辑 browserslist 配置时,你可能会注意到你的更改不会立即生效。这是因为 babel-loader 中的问题 未检测到 package.json 中的变化。一个快速的解决方案是删除 node_modules/.cache 文件夹并重试。

¥When editing the browserslist config, you may notice that your changes don't get picked up right away. This is due to an issue in babel-loader not detecting the change in your package.json. A quick solution is to delete the node_modules/.cache folder and try again.