在dva框架和create-react-app创建出来的框架中修饰器语法与按需加载引入antd分别配置...
2019-08-18 17:01
1161 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yulinjiayuan/article/details/99712090
// export default WrappedNormalLoginForm; 抛出的是这个改变后的变量 而不是Login这个组件了 使用后 @Form.create({ name: 'normal_login' }) 注意这里不要加分号 放在class上面 export default Login
按需加载需要的包 babel-plugin-import 装饰器语法需要的包 @babel/plugin-proposal-decorators
dva框架
将.webpackrc 改成.webpackrc.js然后具体配置
const config = {}; config.proxy = { "/api": { "target": "http://localhost:7001", "changeOrigin": true, "pathRewrite": { "^/api": "" } } } config.extraBabelPlugins = [ //antd按需加载引入 ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }], //装饰器语法配置 [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ] export default config;
在 creat-react-app创建的脚手架配置
建个.babelrc
1 { 2 "presets": [ 3 "react-app" 4 ], 5 "plugins": [ 6 [ 7 "import", 8 { 9 "libraryName": "antd", 10 "libraryDirectory": "es", 11 "style": "css" // `style: true` 会加载 less 文件 12 } 13 ], 14 [ 15 "@babel/plugin-proposal-decorators", 16 { 17 "legacy": true 18 } 19 ] 20 ] 21 }
装饰器 语法使用之前 拿antd的包为例子
// const WrappedNormalLoginForm = Form.create({ name: 'normal_login' })(Login);// export default WrappedNormalLoginForm; 抛出的是这个改变后的变量 而不是Login这个组件了 使用后 @Form.create({ name: 'normal_login' }) 注意这里不要加分号 放在class上面 export default Login
相关文章推荐
- React实战 | create-react-app@2.x所遇到的问题,支持less语法以及引入Antd并修改Antd的主题颜色
- create-react-app按需加载antd
- creat-react-app搭建的项目中按需引入antd以及配置Less和如何修改antd的主题色
- 详解在create-react-app使用less与antd按需加载
- creat-react-app搭建的项目中按需引入antd以及配置Less和如何修改antd的主题色
- ant-design在create-react-app中配置按需加载组件
- create-react-app脚手架创建react项目,react的基本语法,以及react中的事件绑定
- create-react-app使用antd按需加载的样式无效问题的解决
- 在create-react-app创建的React项目应用中配置JQ、Sass
- 使用create-react-app或者antd创建一个React项目
- Create-React-App创建antd-mobile开发环境
- 在基于 create-react-app 的React项目中进行代码分片、按需加载(code splitting)/ 免webpack配置
- create-react-app 引入 antd 及 解决 antd 样式无法显示的bug
- create-react-app中按需加载引入Ant Design
- Create-React-App创建antd-mobile开发环境
- create-react-app 在run eject后对antd和sass的配置
- create-react-app React脚手架 引入 scss 配置
- Create-react-app+Antd+Less 在项目yarn eject 的情况下进行配置
- create-react-app方式下引入antd
- Create-React-App创建antd-mobile开发环境