[英]Firebase emulator for Cloud Functions not updating the code
我正在使用firebase deploy --only functions
部署以下雲 function:
export const testFunction = functions.https.onCall((data, context) => {
return {"data": "hello"};
});
以及何時使用代碼從客戶端應用程序調用它
var testFunction = firebase.functions().httpsCallable("testFunction");
testFunction().then((result) => {
// Read result of the Cloud Function.
this.data = result.data;
});
它按預期工作。 現在,我想繼續開發 function 在本地模擬器上測試它,所以按照文檔,我將這一行添加到 web 應用程序代碼中(在函數之前)
firebase.functions().useEmulator("localhost", 5001); // for local simulator
然后我運行本地模擬器:
firebase emulators:start --only functions
如果我現在運行客戶端應用程序,我會正確地看到調用通過本地模擬器而不是遠程雲 function。
問題:如果修改代碼,本地 function 不會更新。 我需要再次運行 firebase deploy 才能看到響應的變化。 我怎樣才能在本地部署?
這個計算器解決了這個問題。
解決方案簡而言之:
每次更改代碼后,運行npm run build
以重新編譯代碼。
為代碼中的每個更改自動編譯。 將package.json
文件中的"build": "tsc"
更改為"build": "tsc -w"
,然后在另一個終端 window 中運行模擬器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.