ant Design和ant Design mobile的使用,并实现按需加载
1.全局安装yarn
npm install -g create-react-app yarn
2.创建react项目,并用yarn start 运行
3.引入antd/引入antd-mobile
yarn add antd
yarn add antd-mobile
4.在app.js引入button
pc端
import Button from 'antd/lib/button';
<div className="App">
<Button type="primary">Button</Button>
</div>
移动端
import Button from 'antd-mobile/lib/button';
<div className="App">
<Button type="primary">Button</Button>
</div>
5.修改 src/App.css
,在文件顶部引入 antd/dist/antd.css
pc端
@import '~antd/dist/antd.css';
移动端
@import '~antd-mobile/dist/antd-mobile.css';
6.按需加载模块
yarn add react-app-rewired@2.0.2-next.0
7.修改package.json,绿色替换红色
/* package.json */
"scripts": {
- "start": "react-scripts start",
+ "start": "react-app-rewired start",
- "build": "react-scripts build",
+ "build": "react-app-rewired build",
- "test": "react-scripts test",
+ "test": "react-app-rewired test",
}
8. 根目录创建 config-overrides.js,添加如下代码
module.exports = function override(config, env) {
// do stuff with the webpack config...
return config;
};
9.使用 babel-plugin-import
yarn add babel-plugin-import
10.用下面代码覆盖config-overrides.js的代码
pc端
const { injectBabelPlugin } = require('react-app-rewired');
module.exports = function override(config, env) {
config = injectBabelPlugin(
['import', { libraryName: 'antd', libraryDirectory: 'es', style: 'css' }],
config,
);
return config;
};
移动端
const { injectBabelPlugin } = require('react-app-rewired');
module.exports = function override(config, env) {
config = injectBabelPlugin(
['import', { libraryName: 'antd-mobile', libraryDirectory: 'es', style: 'css' }],
config,
);
return config;
};
11.修改app.css代码
pc端
@import '~antd/dist/antd.css'; // 删除 import Button from 'antd/lib/button'; // 删除 import { Button } from 'antd'; // 添加
移动端
@import '~antd-mobile/dist/antd-mobile.css'; // 删除 import Button from 'antd-mobile/lib/button'; // 删除 import { Button } from 'antd-mobile'; // 添加
12.yarn start重新运行
按照上面的操作就可以了
ant Design和ant Design mobile的使用,并实现按需加载的更多相关文章
- Ant Design React按需加载
Ant Design是阿里巴巴为React做出的组件库,有统一的样式及一致的用户体验 官网地址:https://ant.design 1.安装: npm install ant --save 2.引用 ...
- jquery mobile 请求数据方法执行时显示加载中提示框
在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更 ...
- ant design pro(一)安装、目录结构、项目加载启动【原始、以及idea开发】
一.概述 1.1.脚手架概念 编程领域中的“脚手架(Scaffolding)”指的是能够快速搭建项目“骨架”的一类工具.例如大多数的React项目都有src,public,webpack配置文件等等, ...
- 关于 mobile sui a外链 老是出现加载失败的解决办法
mobile sui 框架里面的a本身都绑了了一个ajax方法,ajax只能处理同域,跨域就会出现问题 ,所以mobile sui 中的a如果是外链的话就会出现加载失败的提示,这种明显的bug,让用户 ...
- Ant Design按需加载
不eject情况下配置antd按需加载 1.安装 react-app-rewired yarn add react-app-rewired 2. 项目根目录下新建 config-overrides.j ...
- React(九)create-react-app创建项目 + 按需加载Ant Design
(1)create-react-app如何创建项目我前面第一章介绍过了,这里就不过多写了, (2)我们主要来说说按需加载的问题 1. 引入antd npm install antd --save 2. ...
- jquery mobile 和phonegap开发总结之三跨域加载页面
跨域加载 一要进行一定的配置见下面 $( document ).bind( "mobileinit", function() { // Make your jQuery Mobil ...
- jQuery Mobile 手动显示ajax加载器,提示加载中...
在使用jQuery Mobile开发时,有时候我们需要在请求ajax期间,显示加载提示框(例如:一个旋转图片+一个提示:加载中...).这个时候,我们可以手动显示jQuery Mobile的加载器,大 ...
- jquery mobile 的loading提示“正在加载...”在不同版本中的不同实现方式
在jquery mobile开发中,在页面的切换.或者ajax获取数据时由于网速慢等其他原因,会有一个加载的时间,如果能在这段时间给一个“正在加载...”的提示,用户体验会更好.下面来简单的介绍一下在 ...
随机推荐
- PHP调用外部程序的方法
很多情况下需要php调用其他程序如shell命令.shell脚本.可执行程序等等,此时需要使用到诸如exec/system/popen/proc_open等函数,每种函数有各自适合使用的场景以及需要注 ...
- PAT L3-001 凑零钱(01背包dp记录路径)
韩梅梅喜欢满宇宙到处逛街.现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债.韩梅梅手边有104枚来自各个星球的硬币,需要请你帮她盘算一下,是 ...
- f5源站获取http/https访问的真实源IP解决方案
1.背景 F5负载均衡设备,很多场景下需要采用旁挂的方式部署.为了保证访问到源站的数据流的request和response的TCP路径一致,f5采用了snat机制.但是这样导致源站上看到的来源IP都是 ...
- 浅谈Java代理二:Cglib动态代理-MethodInterceptor
浅谈Java代理二:Cglib动态代理-MethodInterceptor CGLib动态代理特点: 使用CGLib实现动态代理,完全不受代理类必须实现接口的限制,而且CGLib底层采用ASM字节码生 ...
- centos 7下部署grpc
gRPC 是一个高性能.开源和通用的 RPC 框架,面向移动和 HTTP/2 设计.目前提供 C.Java 和 Go 语言版本,分别是:grpc, grpc-java, grpc-go. 其中 C 版 ...
- how2j网站前端项目——天猫前端(第一次)学习笔记1
首先是公共页面的学习,有页头.页脚和搜索框. 一.页头就是天猫网站的置顶导航栏: 看似简单,实际做起来也不容易. 写html还是比较简单的,撸起袖子就可以写完.可要想做到上图的样式就难了,难就难在CS ...
- setTimeout设置为0的意义
今天再看 Promise 代码时,有个地方用到了setTimeOut函数,但是第2个参数设为0,顿时懵逼了,这是啥意思? function resolve(newValue) { value = ne ...
- wheelView实现滚动选择 三方开源的封装控件 spannableString autofitTextView、PinnedSectionListView SwipeListView等等
wheelView多用于popupwindow用来滚动选择条目 github上的开源三方控件 spannableString autofitTextView.PinnedSectionLi ...
- 使用json要导入什么包
json-lib-2.3-jdk15.jar commons-beanutils-1.7.0.jar commons-httpclient-3.1.jar commons-lang-2.3.jar c ...
- StackExchange.Redis使用以及封装
来源:http://www.cnblogs.com/qtqq/p/5951201.html Redis安装:http://www.runoob.com/redis/redis-install.html ...