React+antd create project and basic configuration

If it is helpful to you, you can like it, and if you have time, you can also comment.

  1. Install Scaffolding Tools
cmd命令:npm install -g create-react-app 或者 cnpm install -g create-react-app
  1. Create a project
    create-react-app reactdemo
    cd to reactdemo
    npm start or yarn start
    After running the project, the browser will automatically open, or you can manually visit http://localhost:3000 in the browser, so that the basic React project will be created up

2. Install antd and possible packages

//路由
npm install react-router-dom --save
//请求
npm install axios --save
//安装UI  --  antd
npm install antd --save  
//按需加载 
npm install react-app-rewired customize-cra babel-plugin-import --save
  1. Modify the configuration in package.json
"scripts": {
    
    
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },
  1. Create a new config-overrides.js file in the project's update directory
const {
    
     override, fixBabelImports,addWebpackAlias } = require('customize-cra')
// fixBabelImports 按需加载antd组件
const path = require('path')

module.exports = override(
    fixBabelImports('import', {
    
    
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: 'css'
    }),
     //路径配置
    addWebpackAlias({
    
    
        ['@']: path.resolve(__dirname, 'src')
    })
)

  1. .At this point, the basic configuration has been deployed. Remember to restart the server.
    The antd official document is attached.

Guess you like

Origin blog.csdn.net/tq1711/article/details/109227211