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%;
}
相关推荐
会编程的土豆28 分钟前
新手前端小细节
前端·css·html·项目
广州华水科技1 小时前
单北斗GNSS在桥梁形变监测中的应用与技术进展分析
前端
我讲个笑话你可别哭啊1 小时前
鸿蒙ArkTS快速入门
前端·ts·arkts·鸿蒙·方舟开发框架
CherryLee_12101 小时前
基于poplar-annotation前端插件封装文本标注组件及使用
前端·文本标注
特立独行的猫a1 小时前
C++轻量级Web框架介绍与对比:Crow与httplib
开发语言·前端·c++·crow·httplib
周航宇JoeZhou1 小时前
JB2-7-HTML
java·前端·容器·html·h5·标签·表单
代码小库1 小时前
【课程作业必备】Web开发技术HTML静态网站模板 - 校园动漫社团主题完整源码
前端·html
珹洺1 小时前
Bootstrap-HTML(二)深入探索容器,网格系统和排版
前端·css·bootstrap·html·dubbo
BillKu1 小时前
VS Code HTML CSS Support 插件详解
前端·css·html
xixixin_1 小时前
【React】中 Body 类限定法:优雅覆盖挂载到 body 的组件样式
前端·javascript·react.js