网上有一些的讲react15升级到react16升级的教程。但是很少从整体讲,都是从单个知识点讲。很多都是只讲react本身的升级,如:PropTypes 引用从react模块改成单独的prop-types模块。但是一般项目的架构都是:react+react-router+redux+react-redux+react-router-redux。所以自己整理一下完整的升级过程。
react15升级到react16涉及以下几个方面:
- react-hot-loader
- proptypes
- react-redux
- react-router
- react-hot-loader 升级最新
- webpack.base.conf.js
if (env === 'development') {
// _loaders.unshift('react-hot');
}
.babelrc
增加react-hot-loader
配置
"plugins": [
"react-hot-loader/babel"
]
React-PropTypes-to-prop-types.js
- Go to the /web directory on your project
npm install global add jscodeshift
, this will add jscodeshift- git clone https://github.com/reactjs/react-codemod.git, this will add react-codemod
- cd
react-codemod && npm install cd ..
jscodeshift -t <codemod-script> <path>
to transform your deprecated code. For example, if you want to fix prop-types errors in jsx files in the components directory, you can run something like:jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js app/components/**/*
[email protected]
版本以上
[email protected]
版本以上(不超过4.0.0)
[email protected]
版本以上(不超过4.0.0)