React-常用命令和配置

常用命令

bash 复制代码
# 创建项目
npx create-react-app my-app

# 安装配套工具
npm i @reduxjs/toolkit react-redux
npm i react-router-dom
npm i sass -D
npm i axios classnames echarts

# 启动项目
cd my-app
npm start

文件夹配置

安装ant

javascript 复制代码
网站:https://ant.design/index-cn/
# 1. 安装
npm i antd --save

# 使用, 导入渲染
import { Button } from "antd"

function App() {
  return (
    <div>
      this is app <Button type="primary">test</Button>
    </div>
  )
}

export default App

配置@路径

javascript 复制代码
# 1. 安装craco
npm i -D @craco/craco

# 2. 配置在项目根目录增加craco.config.js
const path = require("path")
module.exports = {
  webpack: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
}

# 3. 配置命令修改项目根目录package.json
  "scripts": {
  	# react-scripts改成craco 
    "start": "craco start",
    "build": "craco build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

# 4. 使用@就表示项目根目录
@/xxx

# 5. vscode配置目录联想,在项目根目录增加jsconfig.json
{
    "compilerOptions": {
        "baseUrl": "./",
        "paths": {
            "@/*": [
                "scr/*"
            ]
        }
    }
}

浏览器样式reset

复制代码
# 安装
npm install normalize.css

# 在入口js里导入, scr/index.js
import normalize.css

# 配置高度铺面浏览器,scr/index.scss
html,
body {
  margin: 0;
  height: 100%;
}

#root {
  height: 100%;
}
相关推荐
新手村领路人1 小时前
Firefox自定义备忘
前端·firefox
乖女子@@@1 小时前
css3新增-网格Grid布局
前端·css·css3
伐尘2 小时前
【CE】图形化CE游戏教程通关手册
前端·chrome·游戏·逆向
不想吃饭e2 小时前
在uniapp/vue项目中全局挂载component
前端·vue.js·uni-app
非凡ghost2 小时前
AOMEI Partition Assistant磁盘分区工具:磁盘管理的得力助手
linux·运维·前端·数据库·学习·生活·软件需求
UrbanJazzerati2 小时前
前端入门:margin居中、border、box-radius、transform、box-shadow、mouse事件、preventDefault()
前端·面试
蝎子莱莱爱打怪2 小时前
🚀🚀🚀嗨,一起来开发 开源IM系统呀!
前端·后端·github
Enddme2 小时前
《前端笔试必备:JavaScript ACM输入输出模板》
前端·javascript·面试
前端鱼2 小时前
前端面试中值得关注的js题
前端·面试
UnnamedOrange3 小时前
有来前后端部署
前端·后端