As Salesforce developers, we’ve all experienced the frustration of slow deployment cycles, endless refreshes, and debugging directly in a sandbox. What if you could preview and test your Lightning Web Components (LWCs) instantly—without deploying to an org?
Enter the Lightning Local Development Server—a game-changer that lets you build, test, and preview LWCs right on your local machine. Whether you're working on standalone components or integrating with mock data, this tool will drastically improve your development speed and experience.
Prerequisites
To use Local Development:
-
Install the Salesforce Command Line Interface (CLI)
Install the Local Dev
-
Enable Local Dev
How to Set It Up
Setting up the Local Development Server is simple. Follow these steps:
1. Install Salesforce CLI
Salesforce CLI is a command-line tool that helps interact with Salesforce from your computer. Install it from Salesforce CLI Download.
2. Enable Local Development in Your Salesforce Org
To turn on this feature for your production or sandbox org, from Setup, in the Quick Find box, enter Local Dev and then select Local Dev. Select Enable Local Dev to turn on the feature for all org users.
3. Enable Local Dev in Your Scratch Org
In your SFDX project, open the file config/project-scratch-def.json.
In the settings section of the file, add the key "enableLightningPreviewPref" and set it to true, like this:
4. Install the Local Development Server Plugin
Install the local dev server using this command "sf plugins install @salesforce/plugin-lightning-dev"
This installs the plugin that allows you to run the Local Development Server.
5. Start the Server
Run this command in terminal and enjoy the show "sf lightning dev app"
As shown in the video it will give you the option to choose the Salesforce Application and the device where you want to use the local dev server.
Preview a Single Component (Beta)
To run a preview of a single LWC in your browser using Local Dev, use the sf lightning dev component
CLI command. For now, you can only preview simple components. For example, components that rely on Lightning Data Service wire adapters (@wire
) or platform modules (force/*
and some lightning/*
modules) aren't supported in single component preview mode.
Run the single component preview command with the following feature flags. If you forget to set a needed flag, don't worry: the CLI will prompt you to select a value for it from a list of valid options.
Checkout Complete Video Tutorial Below
0 Comments