create-react-app兼容ie11配置

今天閒來無事折騰一下create-react-app,發現主流瀏覽器都沒有問題。可是ie11卻一直報錯,真是倔強的很啊。
我翻了下create-react-app的文檔,從中看到了正好有對ie九、ie十、ie11的兼容性問題解決的一個方案。這時須要用到react-app-polyfill這個插件。node

文檔地址:
https://facebook.github.io/create-react-app/docs/supported-browsers-features
create-react-app github地址:
https://github.com/facebook/create-react-app/tree/master/packages/react-app-polyfill react

下載安裝這個插件
npm install react-app-polyfill
而後在src下的index.js也就是js入口文件中首行寫入webpack

import "react-app-polyfill/ie11";
import "react-app-polufill/stable";
image.png
而後根據官網的提示,還須要在package.json文件中的browserslist中添加ie11
image.png
最後從新運行項目發現仍是空白可是瀏覽器沒有報錯,把node_moudles刪掉從新安裝或者刪除目錄下面的.cache後從新npm start就能夠正常打開了。git

若是create-react-app是3.3.0版本的話還須要修改另一個地方,IE11纔不會報錯。
issue:https://github.com/facebook/c...
./node_modules/react-dev-utils/webpackHotDevClient.js:60增長slashes: true
image.png
至此就能在IE11上面看到熟悉的標誌啦。
image.pnggithub

相關文章
相關標籤/搜索