如何發布react app

2021-10-05 20:42:45 字數 844 閱讀 3129

npm run build
2.開啟終端,將產生的build檔案複製到在伺服器root目錄下。

3.終端安裝node

yum install nodejs
出現:is this ok [y/d/n]: 

輸入y4 終端輸入

npm -v
檢視node是否安裝成功

5.安裝serve

npm install -g serve
如果不安裝serve,後面輸入serve會報錯:-bash: serve: command not found

6.在伺服器的build目錄下輸入

serve -s
報錯:const updatecheck = async (isdebugging) => {

syntaxerror: unexpected token (

是因為node版本太低,需要公升級node

7.公升級node到最新版本

npm install -g n
n latest
下面是安裝babel,如果上面的步驟執行完後,輸入serve -s,能正常執行,可以不安裝babel

npm install -g babel-preset-react
8.繼續執行serve

serve -s
結果如下:on your network:  

訪問該位址,成功

react app 編寫測試

jest enzyme 文件 為什麼要寫測試 單元測試 unit testing 指的是以軟體的單元 unit 為單位,對軟體進行測試。單元可以是乙個函式,也可以是乙個模組或元件。它的基本特徵就是,只要輸入不變,必定返回同樣的輸出。準備所有的測試條件 it test a it test b 呼叫 觸...

react app 專案開發 2 axios

生產環境打包並執行 yarn run build 會src 進行打包處理,在記憶體中生成打包檔案 將打包檔案儲存至記憶體 yarn global add serve serve s build 將 build 資料夾下所有資源載入到記憶體中 啟動伺服器,執行記憶體中的打包檔案,通過瀏覽器訪問 url...

react app 學習(4) 書寫函式的方式

函式書寫的幾種方式 方式一 箭頭函式書寫方式 以及使用bind來繫結 class cnheadertime extends component render change color time 91 seconds 倒計時 timecut time.innertext total 1000 方式二 ...