react项目搭建和首次git推送
react项目初始化以及配置别名步骤
1,执行 npx create-react-app react-bill
2,执行 npm i
3,执行 npm i @reduxjs/toolkit react-redux react-router-dom dayjs classnames antd-mobile axios
4,然后把项目中的多余文件和代码清掉去:
5,初始化app.js文件如下:
function App() {
return (
<div className="App">
this is app
</div>
);
}
export default App;
6,删除 App.css App.test.js logo.svg reportWebVitals.js setupTests.js
<React.StrictMode>是严格模式,它会让一些钩子函数执行两次,会造成一些你疑惑的点
7,初始化入口文件index.js如下:
import React from 'react'
import ReactDOM from 'react-dom/client'
import './index.css'
import App from './App'
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(<App />)
全程就只剩下 App.js index.css index.js文件
8,然后执行 npm run start
git首次项目推送到远程仓库
1,在github上点击头像有一个 Your repositories选项,点击
2,然后点击右上角的绿色按钮 New
3,找到Repository name 然后输入你自己的仓库名,自定义,如:reactBill
4,找到 Description,输入你自己的项目描述,自定义输入
6,然后找到 Add a README file,勾选上
7,然后点击右下角绿色的按钮 Create repository
创建好仓库后,首次本地项目react-bill推送到远程仓库
git init
git add.
git commit -m 'project init’此时会提示要绑定用户
执行:git config --global user.email “xxx”
git config --global user.name “xxx”
git commit -m ‘project init’
git remote add origin github.com/xxx/reactBi… (这是你的远程仓库地址)
git push origin master -u (此时会弹出要你输入账号和密码)
然后输入账号和密码在推送一次
git push origin master -u