需要理解的概念有:
需要理解的概念有:
React的UI框架有哪些
Antd的完整安装与使用
import React, { Component } from 'react';
import { DatePicker } from 'antd';
import 'antd/dist/antd.css';
// 需要引入样式内容,否则界面无样式效果
export default class App extends Component {
render() {
return (
);
}
}
常用组件的使用
需要理解的概念有: npm run build 压缩打包
antd
的 JS 代码默认支持基于 ES modules 的 tree shaking{
"name": "hello-react",
...
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
...
}
react是基于webpack配置运行的,但是我们看不到任何的webpack配置,只能用eject进行弹射时才能查看。
为社么使用require? 因为webpack是基于commonjs的
webpack基于五大核心概念:入口 出口 加载器 模式 插件
const CracoAntDesignPlugin = require('craco-antd');
//设置了一个插件
module.exports = {
plugins: [{ plugin: CracoAntDesignPlugin }],
};
App.js,去除css的引入
import React, { Component } from 'react';
import { DatePicker } from 'antd';
export default class App extends Component {
render() {
return (
);
}
}
需要理解的概念有:
App.js,引入less
import React, { Component } from 'react';
import { DatePicker } from 'antd';
import './App.less';
export default class App extends Component {
render() {
return (
<div>
<DatePicker />
</div>
);
}
}
App.less,引入less
@import '~antd/dist/antd.less';
//安装插件
const CracoLessPlugin = require('craco-less');
const CracoAntDesignPlugin = require('craco-antd');
module.exports = {
plugins: [
{ plugin: CracoAntDesignPlugin },
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
modifyVars: { '@primary-color': '#ffcc00' },
// 设置自定义主题样式
// 配置参数:https://ant.design/docs/react/customize-theme-cn
javascriptEnabled: true,
},
},
},
},
],
};
需要理解的概念有:
react项目的创建
UI框架的安装与使用
antd-mobile的安装使用与配置
https://mobile.ant.design/docs/react/use-with-create-react-app-cn
npm i antd-mobile --save
# less与less-loader需要指定版本,如果按最新版本会出现兼容性错误问题以及less语法等后续问题 按需加载
npm i babel-plugin-import customize-cra react-app-rewired [email protected] [email protected] --sav-dev
package.json
{
"name": "react-mobile",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"antd-mobile": "^2.3.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"babel-plugin-import": "^1.13.3",
"customize-cra": "^1.0.0",
"less": "^3.13.1",
"less-loader": "^7.3.0",
"react-app-rewired": "^2.1.8"
}
}
const { override, fixBabelImports } = require('customize-cra');
module.exports = function override(config, env) {
// do stuff with the webpack config...
return config;
};
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd-mobile',
style: 'css',
})
);
public/index.html
https://mobile.ant.design/docs/react/introduce-cn#3.-%E4%BD%BF%E7%94%A8
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<script src="https://as.alipayobjects.com/g/component/fastclick/1.0.6/fastclick.js">script>
<script>
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function () {
FastClick.attach(document.body);
}, false);
}
if (!window.Promise) {
document.writeln('