Skip to content

☁️ Salesforce DX project template with Prettier, Linter, Git-Hooks and VS Code settings

License

Notifications You must be signed in to change notification settings

svierk/sfdx-project-starter-kit

Repository files navigation

☁️ Salesforce DX Project Starter Kit

GitHub CI Quality Gate Status codecov FOSSA Status

About the project

The repository provides a template for Salesforce DX projects which includes an initial configuration of Prettier, Linter rules, git hooks and unit tests as well as useful VS Code settings.

Prerequisites

To use this template, the Node version specified in the package.json and the latest version of the Salesforce CLI should already be installed.

Getting started

To get the template up and running, you need to clone the repository and open it with VS Code, install all the recommended extensions and run the following command to install all required dependencies:

npm install

After that you need to authorize an org for which you want to develop. In VS Code this can be done by pressing Command + Shift + P, enter "sfdx", and select SFDX: Authorize an Org.

Alternatively you can also run the following command from the command line:

sf org login web

Code scaffolding

To generate new components in VS Code, press Command + Shift + P, enter "sfdx create", and select what you want to create, e.g. SFDX: Create Lightning Web Component.

Alternatively you can also create all components from the command line, e.g.:

cd force-app/main/default/lwc
sf lightning generate component --type lwc -n helloWorld -d force-app/main/default/lwc

Code quality

Git hooks

The project includes client-side pre-commit git hooks using husky and lint-staged. After installing all project dependencies, Prettier, Linter and unit tests are automatically executed before each commit.

Prettier

Run Prettier to check all files for formatting issues:

npm run prettier

Linter

Linting LWC and Aura

Run ESLint to check for linting issues:

npm run lint

Linting Apex code

Use the recommended extension Apex PMD to check manually for Apex linting issues.

Unit tests

Execute LWC unit tests with Jest

To execute all unit tests only once run:

npm run test:unit

To execute all unit tests in watch mode for development run:

npm run test:unit:watch

To execute all unit tests with generated code coverage run:

npm run test:unit:coverage

Local development

LWC development server

Lightning Web Components can be developed locally without the need to push them to an org first. To set up local development you only need to authorize an org and install the development server.

The local development server and its configuration are provided by a Salesforce CLI plugin that can be installed as follows:

sf plugins install @salesforce/lwc-dev-server

To start the server on http://localhost:3333 and access all components of the project run:

npm run server:lwc

Debugging

To debug and troubleshoot Lightning Web Components, in addition to enabling Debug Mode in Salesforce, you should also configure the following settings in Chrome Dev Tools:

  • Enable custom formatters under Settings --> Preferences

  • User the Ignore List to ignore framework code while troubleshooting. Add the following two patterns under Settings --> Ignore List:

    • /aura_prod.*.js$
    • /components/.*.js$

Read more about Salesforce DX development