【Procedure】如何搭建VSCode的開發環境
要件
- 使用 Trailhead PlayGround 的 scratch 環境開發
- 作成任意一個 lightning web components
- JDK8 以上
手順
- 準備工作
1; 安裝Salesforce CLI
2; 安裝Visual Studio Code
3;DEV Hub有效 - 工程作成
- 環境Deploy
準備工作
安裝Salesforce CLI
sfdx plugins --core
安裝Visual Studio Code
- Visual Studio Code
- 安裝擴展插件
1;Salesforce Extension Pack
2;XML
DEV Hub有效
使用 Trailhead Playground 作爲 Dev Hub 來管理 scratch 環境。
- 啓動 Trailhead Playground
- 進入【設定】
- 快速檢索欄檢索【Dev Hub】
- 有效化
Salesforce DX工程作成
VSCode的命令面板中,[SFDX: Create Project (SFDX: 工程作成)]選擇,名稱,路徑設定後,自動生成。
或者
sfdx force:project:create -n NAMEXXX -d DIRECTORYXXX
Scratch開發環境設置
承認DEV Hub
VSCode的命令面板中, [SFDX: Authorize Dev Hub (SFDX: Dev Hub 承認)]
或者
sfdx force:auth:web:login -d
創建開發的Scratch環境
VSCode的命令面板中,[SFDX: Create a Default Scratch Org]
或者
sfdx force:org:create -f config\project-scratch-def.json -a trailhead -d 7 -s --json --loglevel fatal
-f 組織定義文件
-a 組織的別名
-d 組織存活的天數,缺省7天,7天后自動刪除該組織(因爲不同版本有不同數量的限制)
-s 設定創建的該組織作爲缺省的用戶名
--json 輸出json格式
--loglevel log的輸出等級
作成LWC組件
sfdx force:lightning:component:create -n myFirstWebComponent -d force-app/main/default/lwc --type lwc
-n 組件名稱
-d 組件的保存目錄,要求在lwc目錄下
--type 表示作成LWC組件
修改一些代碼(省略)
Deploy代碼
推送meta數據到Scratch環境
sfdx force:source:push
確認已做成的組件
sfdx force:org:open
打開Scratch環境後,可以看到已做成的組件