Create Lightning Web Components

You can use Salesforce CLI to create Lightning web components in your local Salesforce DX project. The generated files live in a lwc directory in a package directory of your project.

Want to develop your Lightning web components in a real-time preview of your Lightning app or Experience Cloud site? Try the new Local Dev experience, which lets you iterate faster on your components without deploying code or manually refreshing the preview.

Note

  1. Open a terminal (macOS and Linux) or command prompt Windows and change to your Salesforce DX project directory.
  2. Create the lwc directory in the location you want to generate the Lightning app and Aura components. For example, if you want to generate them in the default package directory, create the force-app/main/default/aura directory if it doesn’t exist.
  3. Create the Lightning web component; specify the component name with the --name flag and the lwc directory with the --output-dir flag.
    sf lightning generate component --type lwc --name myLightningWebComponent --output-dir force-app/main/default/lwc

Use the project deploy start command to deploy your new Lightning web component to your org.

sf project deploy start --metadata LightningComponentBundle:myLightningWebComponent