Comments (6)
小结一下,使用 antd-init
v1.1.2 生成的脚手架,需要作以下改动才可以在 IE8 下运行:
-
index.html
需要引入 polyfill:<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.9.1/polyfill.min.js"></script> <script src="common.js"></script> <script src="index.js"></script>
或者运行
npm i --save babel-polyfill
安装依赖,然后在 entries 文件最开头import "babel-polyfill"
。 -
生成的
package.json
中dependencies
一节,将以下的依赖:"isomorphic-fetch": "^2.2.1", "js-cookie": "^2.1.1", "react": "^15.0.2", "react-dom": "^15.0.2", "react-redux": "4.4.x", "react-router": "^2.0.1", "react-router-redux": "^4.0.1", "redux": "^3.5.2", "redux-actions": "0.9.x", "redux-saga": "^0.10.4"
修改为:
"fetch-ie8": "^1.4.2", "js-cookie": "^2.1.1", "react": "0.14.x", "react-dom": "0.14.x", "react-redux": "4.4.x", "react-router": "2.3.x", "react-router-redux": "4.0.x", "redux": "^3.5.2", "redux-actions": "0.9.x", "redux-saga-ie8": "0.10.x",
保存后运行
npm i
重新安装依赖。 -
文件中相应的引用也需要更改:
-
entries/index.js
// import { syncHistoryWithStore, routerReducer as routing } from 'react-router-redux'; // https://github.com/xcatliu/react-ie8/issues/26 import syncHistoryWithStore from 'react-router-redux/lib/sync'; import { routerReducer as routing } from 'react-router-redux/lib/reducer';
-
sagas/index.js
// import { fork } from 'redux-saga/effects'; import { fork } from 'redux-saga-ie8/effects';
-
sagas/SagaManager.js
// import { take, fork, cancel } from 'redux-saga/effects'; import { take, fork, cancel } from 'redux-saga-ie8/effects';
-
sagas/todos.js
// import { takeLatest } from 'redux-saga'; import { takeLatest } from 'redux-saga-ie8'; // import { take, call, put, fork, cancel } from 'redux-saga/effects'; import { take, call, put, fork, cancel } from 'redux-saga-ie8/effects';
-
services/xFetch.js
// import fetch from 'isomorphic-fetch'; import 'fetch-ie8';
-
-
还有一些兼容 IE8 必须的小改动:
-
services/todos.js
import xFetch from './xFetch'; // export async function getAll() { // 用了 async 关键字 IE8 会出错 export function getAll() { return xFetch('/api/todos'); }
-
-
另外参考 antd-init 的使用说明:
-
在
webpack.config.js
中开启es3ify-loader
:// Enable this if you have to support IE8. - // webpackConfig.module.loaders.unshift({ - // test: /\.jsx?$/, - // loader: 'es3ify-loader', - // }); + webpackConfig.module.loaders.unshift({ + test: /\.jsx?$/, + loader: 'es3ify-loader', + });
-
在
package.json
的scripts
一节中添加兼容 IE8 的服务器命令:"start": "dora --plugins \"proxy,webpack,webpack-hmr,livereload?enableJs=false&injectHost=127.0.0.1,browser-history?index=/src/entries/index.html\"", + "start:ie8": "dora --plugins \"proxy,webpack,livereload?enableJs=false&injectHost=127.0.0.1,browser-history?index=/src/entries/index.html\"",
然后用
npm run start:ie8
运行服务器。
-
-
至此脚手架已可以在 IE8 下运行了,但仍有不完善之处。脚手架默认启用
react-router
的browserHistory
,可惜 IE8/9 不支持,这时react-router
会以整页刷新来代替不刷新网页修改地址栏 URL。因此点击脚手架网页左侧的链接时,起不到实时过滤的效果(在改变了勾选项后看得更清楚)。所以要在 IE8 下有更好的用户体验,请改用hashHistory
:-
entries/index.js
// import { browserHistory } from 'react-router'; import { hashHistory } from 'react-router'; // const history = syncHistoryWithStore(browserHistory, store); const history = syncHistoryWithStore(hashHistory, store);
-
from antd-init.
from antd-init.
开启了。
报的是调试工具里引入的错。
from antd-init.
试过这样改之后可以:
- https://github.com/ant-design/antd-init/blob/master/boilerplates/plain-react/webpack.config.js#L15-L19
开启这一行。 - react-router 换成 2.3
- react 和 react-dom 换成 0.14
- 修改 package.json,删除 hmr 插件
代价好大。。
from antd-init.
from antd-init.
好,给个 hint 就行...
from antd-init.
Related Issues (20)
- 静态数据不加载,不知道如何调试 HOT 1
- How to use webpack2 customized the antd theme and icon url. HOT 4
- antd主题切换 HOT 3
- antd主题切换后自定义的css被覆盖的问题 HOT 1
- 自定义主题后,pagination组件按钮样式异常
- theme:导入报错小细节
- theme:导入报错小细节 HOT 1
- build后报错,该如何解决
- 如果我用的脚手架不是antd-init 和 dva-cli呢?该怎么处理? HOT 1
- 如何针对不同的entry做不同的modifyVars HOT 2
- 自定义iconfont路径只能用绝对路径? HOT 2
- 如何获取Icon的style值以及动态的改变style?
- 使用 parceljs ,本地部署 Iconfont 失败
- 想问下,不想修改整个主题,只想要修改某个组件的样式应该怎么做? HOT 1
- 在antd-pro中使用图标本地化时,报错
- Invalid setting font-family HOT 1
- my theme does not change help
- Translate this example to english
- 请问如果使用package.theme来自定义iconfont的路径无效,可以参考这个解决方案。
- 提错地方了,请无视 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from antd-init.