[英]`react-hover` npm package not in production build but working fine in development
[英]React production build not working with IE 11
我的反應項目使用 express 作為后端。 當我在開發模式下使用 React 的“npm start”和 Express 服務器的“node server.js”運行項目時,我可以在 chrome 和 IE 11 中使用它。當我使用“npm run”創建生產構建時build”並使用“node server.js”運行它,它在Chrome中工作,但在IE 11中不起作用。 我在控制台中沒有看到任何錯誤。
我在 index.js 開頭使用以下語句來使代碼與 IE 11 兼容。
導入 'core-js/es6/map'; 導入 'core-js/es6/set'; 導入 'raf/polyfill';
React 版本 - 16. 使用 create-react-app 創建的項目。
我認為它不起作用,因為 webpack.config.prod.js 沒有捆綁 IE 11 兼容代碼。
你應該使用:react-app-polyfill
該軟件包包括適用於各種瀏覽器的 polyfill。 它包括 Create React App 項目使用的最低要求和常用語言功能。
用法 首先,使用 Yarn 或 npm 安裝包:
npm install react-app-polyfill
或者
yarn add react-app-polyfill
對於 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 支持所有流行的瀏覽器,包括 Internet Explorer 9 及更高版本,盡管舊版瀏覽器(例如 IE 9 和 IE 10)需要一些 polyfill。
安裝這兩個包。
npm install babel-polyfill
npm install react-app-polyfill
這必須是 src/index.js 的第一行
import "react-app-polyfill/ie9"
import "react-app-polyfill/ie11"
import "react-app-polyfill/stable"
import 'raf/polyfill';
您還可以使用以下文檔配置您的清單以處理不同的瀏覽器: https : //github.com/browserslist/browserslist
例子 :
"browserslist": [
">0.2%",
"not dead",
"ie >= 9" ]
導入“react-app-polyfill/ie11”
導入“react-app-polyfill/stable”
第二行(react-app-polyfille/stable)對我有用。 我試圖在使用 ie11 呈現頁面的桌面應用程序中加載反應頁面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.