@1o1w1/react-app-polyfill 中文文档教程

发布于 6年前 浏览 22 项目主页 更新于 3年前

react-app-polyfill

这个包包括各种浏览器的 polyfill。 它包括 Create React App 项目使用的最低要求和常用语言功能。

Usage

首先,使用 Yarn 或 npm 安装包:

npm install react-app-polyfill

或者

yarn add react-app-polyfill

Supporting Internet Explorer

您可以导入您打算支持的最小版本的入口点,以确保存在使用 Create React App 所需的最小语言功能。 例如,如果您导入 IE9 入口点,这将包括 IE10 和 IE11 支持。

这些模块确保存在以下语言功能:

  1. Promise (for async / await support)
  2. window.fetch (a Promise-based way to make web requests in the browser)
  3. Object.assign (a helper required for Object Spread, i.e. { ...a, ...b })
  4. Symbol (a built-in object used by for...of syntax and friends)
  5. Array.from (a built-in static method used by array spread, i.e. [...arr])

如果您需要更多功能,请参阅下面的Polyfilling 其他语言功能部分。

Internet Explorer 9

// This must be the first line in src/index.js
import 'react-app-polyfill/ie9';

// ...

Internet Explorer 11

// This must be the first line in src/index.js
import 'react-app-polyfill/ie11';

// ...

Polyfilling other language features

您还可以填充目标浏览器中不可用的稳定语言功能。 如果您在 Create React App 中使用它,它会自动使用您定义的 browserslist 在导入 stable polyfill 时仅包含目标浏览器所需的 polyfill。 如果您需要在您的应用程序中支持 Internet Explorer,请确保遵循上述 Internet Explorer 步骤

// This must be the first line in src/index.js
import 'react-app-polyfill/stable';

// ...

如果您支持 Internet Explorer 9 或 Internet Explorer 11,则应包括 ie9ie11stable 模块:

对于 IE9:

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

// ...

对于 IE11:

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

// ...

react-app-polyfill

This package includes polyfills for various browsers. It includes minimum requirements and commonly used language features used by Create React App projects.

Usage

First, install the package using Yarn or npm:

npm install react-app-polyfill

or

yarn add react-app-polyfill

Supporting Internet Explorer

You can import the entry point for the minimal version you intend to support to ensure that the minimum language features are present that are required to use Create React App. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.

These modules ensure the following language features are present:

  1. Promise (for async / await support)
  2. window.fetch (a Promise-based way to make web requests in the browser)
  3. Object.assign (a helper required for Object Spread, i.e. { ...a, ...b })
  4. Symbol (a built-in object used by for...of syntax and friends)
  5. Array.from (a built-in static method used by array spread, i.e. [...arr])

If you need more features, see the Polyfilling other language features section below.

Internet Explorer 9

// This must be the first line in src/index.js
import 'react-app-polyfill/ie9';

// ...

Internet Explorer 11

// This must be the first line in src/index.js
import 'react-app-polyfill/ie11';

// ...

Polyfilling other language features

You can also polyfill stable language features not available in your target browsers. If you're using this in Create React App, it will automatically use the browserslist you've defined to only include polyfills needed by your target browsers when importing the stable polyfill. Make sure to follow the Internet Explorer steps above if you need to support Internet Explorer in your application.

// This must be the first line in src/index.js
import 'react-app-polyfill/stable';

// ...

If you are supporting Internet Explorer 9 or Internet Explorer 11 you should include both the ie9 or ie11 and stable modules:

For IE9:

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

// ...

For IE11:

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

// ...
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文