第一個 React 專案
以下使用 Vite 建立第一個 React 前端專案,並顯示 `Hello React`。
## 1. 建立 Vite 專案
先確認已安裝 Node.js,接著在終端機執行:
```bash
npm create vite@latest hello-react
```
依提示選擇:
```text
Project name: hello-react
Select a framework: React
Select a variant: JavaScript
```
也可以直接使用指令建立:
```bash
npm create vite@latest hello-react -- --template react
```
## 2. 安裝相依套件
進入專案目錄並安裝套件:
```bash
cd hello-react
npm install
```
## 3. 修改 React 畫面
開啟:
```text
src/App.jsx
```
將內容改成:
```jsx
function App() {
return <h1>Hello React</h1>
}
export default App
```
## 4. 啟動開發伺服器
```bash
npm run dev
```
成功後,終端機會顯示類似:
```text
Local: http://localhost:5173/
```
使用瀏覽器開啟該網址,即可看到:
```text
Hello React
```
相關學習地圖、教學課程
F2E 網站前端工程