2 專案作品 - Vite建立React專案及安裝套件


Posted by mijouhsieh on 2024-07-23

初次用 Vite來建立專案,比較一下和 CRA 的差異,以及需要安裝哪些套件。

1之前使用 CRA 建立 React專案,是使用 react-scripts 來啟動專案。

而 Vite 不需要 react-scripts。

//CRA package.json
"scripts": {
    "start": "react-scripts start",
    "dev-server": "json-server --watch db.json --port 3001",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
//Vite package.json
 "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },

2 index.html 的位置移到專案根目錄中

cra-vs-vite-indexhtml.png


安裝套件

使用 Sass 來編寫樣式 npm install node-sass

設定路由 npm i react-router-dom@6.4.1


#install plugs #安裝套件 #react-router-dom #路由







Related Posts

Day 164

Day 164

01-先從外觀說起就對了!

01-先從外觀說起就對了!

迭代陣列 for...of, filter( )

迭代陣列 for...of, filter( )


Comments