antd-demo 用 create-react-app 构建的前端工程
front_end
back_end 后端工程
创建后端工程目录 back_end
-
安装 node
设置npm的镜像源
npm config set registry http://registry.npm.taobao.org/ -
安装 create-react-app
npm install -g create-react-app
-
构建前端工程 antd-demo
create-react-app antd-demo
或者
yarn create react-app antd-demo 如果是windows平台,msys2终端中调用可能有问题,直接在cmd中执行 -
引入antd(优先用yarn添加依赖)
yarn add antd
或者
npm install antd --save -
自定义配置
5.1 安装 react-app-rewired customize-crayarn add react-app-rewired customize-cra
5.2 修改 package.json
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},5.3 新建 config-overrides.js
module.exports = function override(config, env) {
// do stuff with the webpack config...
return config;
};5.4 安装 babel-plugin-import 并修改 config-overrides.js
yarn add babel-plugin-import
const { override, fixBabelImports } = require ('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: 'css',
}),
);5.5 自定义主题安装 less less-loader 并修改 config-overrides.js
yarn add less less-loader 修改config-overrides.js文件
const { override, fixBabelImports, addLessLoader } = require('customize-cra');
module.exports = override(
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}),
addLessLoader({
javascriptEnabled: true,
modifyVars: { '@primary-color': '#1890ff' },
}),
);
-
mkdir antd-umi
-
npm init -y
-
npm install umi --save-dev
-
新建umi的配置文件 config/config.js(或.umirc.js)二选一
-
npm install umi-plugin-react --save-dev
-
npm install serve -g
-
mkdir front_end
-
创建umi
yarn create umi
或者
npm create umi
选择 app -> typescript(N) -> antd & dva -
安装依赖
yarn
或者
npm install -
全局安装npx
yarn global add npx
-
创建页面路由
npx umi g page products