本頁面說明如何在單一工作區和多資料夾工作區中管理多個 Cloud Functions 設定,以及如何使用 Cloud Code 重新排列 Cloud Run 函式探索器。
事前準備
本指南需要您先設定工作區 (launch.json
檔案,其中至少列出一個設定)。如要開始使用範例,請參閱「建立及部署函式」快速入門導覽課程。
在單一工作區中管理多個設定
如要將新的 Cloud Function 設定新增至 launch.json
檔案,請按照下列步驟操作:
按一下「Cloud Code」,然後展開「Cloud Functions」探索工具。
在 Cloud Run 函式探索器中,將游標懸停在「工作區」上,然後按一下「新增雲端函式設定」。
按照提示操作,並執行下列動作:
- 輸入函式名稱
- 選取 Cloud Run 函式環境
- 輸入進入點 (要呼叫此函式的名稱)
- 輸入測試輸入內容
或者,您也可以手動在
launch.json
檔案中輸入這些值:{ "configurations": [ { "name": "Deploy Cloud Function", "type": "cloudcode.cloudfunctions", "request": "launch", "functionName": "hello-world-get", "gen": "GEN_2", "entryPoint": "helloGet" } ] }
Cloud Run 函式工作區會對應至
launch.json
檔案中列出的首個設定。工作區名稱會反映launch.json
檔案中列出的第一個設定的functionName
:{ "configurations": [ { "name": "Deploy Cloud Function", "type": "cloudcode.cloudfunctions", "request": "launch", "functionName": "hello-world-pub-sub", "gen": "GEN_2", "entryPoint": "helloPubSub" }, { "name": "Deploy Cloud Function", "type": "cloudcode.cloudfunctions", "request": "launch", "functionName": "hello-world-get", "gen": "GEN_2", "entryPoint": "helloGet" } ] }
(選用) 如要從
launch.json
檔案部署其他設定,請將要部署的設定移至launch.json
檔案頂端,然後按一下「更新」「Cloud Functions Explorer」。
管理多資料夾工作區
如果每個函式都包含自己的 launch.json
檔案,Cloud Code 就會支援在 Cloud Run 函式工作區中建立多個資料夾。
每個顯示的 Cloud Run 函式工作區資料夾,其名稱都取自對應 launch.json
檔案中第一個設定的 functionName
。
如要為專案安排多資料夾工作區,請參閱 VS Code 的多根目錄工作區。
將 Cloud Run 函式 Explorer 重新排列至 IDE 的檔案 Explorer
您可以執行下列操作,將 Cloud Run 函式 Explorer 重新排列至 VS Code 的檔案 Explorer:
將 Cloud Run 函式 Explorer 拖曳至 VS Code 的檔案總管:
這種安排會在檔案總管下方顯示 Cloud Run 函式總管,讓您能夠在與專案檔案相同的窗格中,查看已部署的函式和 Cloud Run 函式工作區。
(選用) 如要復原這項安排,請在「Cloud Code: Cloud Functions」探索器標題上按一下滑鼠右鍵,然後選取「Reset location」。這會將 Cloud Run 函式探索器移回「Cloud Code」分頁。