To create a Lightning web component from the CLI, you must have an lwc directory in your Salesforce DX project.
The Salesforce Developer Experience (DX) is a set of tools that streamlines the entire development life cycle. It improves team development and collaboration, facilitates automated testing and continuous integration, and makes the release cycle more efficient and agile. source
So let's go through each step and set up the Salesforce DX
Salesforce CLI supports the following operating systems.
1. Scratch Org - It is a source-driven and disposable deployment of Salesforce code and metadata. Scratch Orgs are driven by source, Sandboxes are copies of production.
Note - Scratch orgs do not replace sandboxes
2. Dev Hub - It is the main Salesforce org that you will use to create and manage your scratch orgs.
Setup
, enter Dev Hub in the Quick Find box and select Dev HubNote - After you enable Dev Hub, you can’t disable it.
Visual Studio Code: It is a source code editor developed by Microsoft for Windows, Linux, and macOS. It is a super fast and lightweight Source Code Editor, which can be used to view, edit, run, and debug source code for applications. Front-end developers mainly use it.
https://visualstudio.microsoft.com/downloads/
Download Salesforce CLI using the appropriate link for your operating system:
S.NO | Operating system | Link |
---|---|---|
1 | macOS | https://sfdc.co/sfdxcliosx |
2 | Windows 32-bit | https://sfdc.co/sfdxcliwin |
3 | Windows 64-bit | https://sfdc.co/sfdxcliwin64 |
4 | Debian/Ubuntu 64 | https://sfdc.co/sfdxclilinux |
5 | Debian/Ubuntu x86 | https://sfdc.co/sfdxclilinux_x86 |
In order to verify the CLI setup is done successfull. Type the below command in Terminal or Command Prompt
sfdx;
If You see something like this, it means CLI is installed successfully.
To work with Lightning web components, you need version 45 or higher of the Salesforce CLI. Check the installed version by running the below command.
sfdx plugins --core
The command outputs version numbers of CLI and plugins like shown below:
Salesforce Extension Pack provides powerful features for working with the Salesforce CLI, the Lightning Component framework, Apex, and Visualforce.
Note: You can’t develop Lightning web components in the Salesforce Developer Console.
In Visual Studio CodeVisual Studio Code, open the Command Palette by pressing Ctrl+Shift+P
on Windows or Cmd+Shift+P
on macOS. Enter sfdx
to filter for commands provided by the Salesforce Extensions.
If You see something like this, it means Salesforce Extension Pack is installed successfully.
A scratch Orgs are temporary Salesforce Orgs where developers will build source code and configure an application.
sfdx: create a default Scratch Org…
. Select the command.Once above process completed it will create a default scratch org associated with your Dev Hub Org.
You can verify the scratch org
sfdx: Open Default org
.Enter
it will open the your org that you have created.