lightning Commands

Use the lightning commands to create Aura components and Lightning web components. As of API version 45.0, you can build Lightning components using two programming models: Lightning Web Components, and the original model, Aura Components. Lightning web components and Aura components can coexist and interoperate on a page.

force:lightning:app:create

Creates a Lightning app bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Help for force:lightning:app:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

Examples:

1$ sfdx force:lightning:app:create -n myapp
1$ sfdx force:lightning:app:create -n myapp -d aura

Command Syntax

sfdx force:lightning:app:create
[--json]
[--loglevel LOGLEVEL]
-n APPNAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --appname APPNAME
Required

The Lightning app name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningApp
Default value: DefaultLightningApp
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string

force:lightning:component:create

Creates a bundle for an Aura component or a Lightning web component in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Help for force:lightning:component:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

To create a Lightning web component, pass --type lwc to the command. If you don’t include a --type value, Salesforce CLI creates an Aura component by default.

Examples:

1$ sfdx force:lightning:component:create -n mycomponent
1$ sfdx force:lightning:component:create -n mycomponent --type lwc
1$ sfdx force:lightning:component:create -n mycomponent -d aura
1$ sfdx force:lightning:component:create -n mycomponent --type lwc -d lwc

Command Syntax

sfdx force:lightning:component:create
[--json]
[--loglevel LOGLEVEL]
-n COMPONENTNAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]
[--type TYPE]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --componentname COMPONENTNAME
Required

The Lightning component name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: default, analyticsDashboard, analyticsDashboardWithStep
Default value: default
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string
--type TYPE
Optional

The type of the new Lightning component.

Type: string
Permissible values are: aura, lwc
Default value: aura

force:lightning:event:create

Creates a Lightning event bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Help for force:lightning:event:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

Examples:

1$ sfdx force:lightning:event:create -n myevent
1$ sfdx force:lightning:event:create -n myevent -d aura

Command Syntax

sfdx force:lightning:event:create
[--json]
[--loglevel LOGLEVEL]
-n EVENTNAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --eventname EVENTNAME
Required

The Lightning event name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningEvt
Default value: DefaultLightningEvt
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string

force:lightning:interface:create

Creates a Lightning interface bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Help for force:lightning:interface:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

Examples:

1$ sfdx force:lightning:interface:create -n myinterface
1$ sfdx force:lightning:interface:create -n myinterface -d aura

Command Syntax

sfdx force:lightning:interface:create
[--json]
[--loglevel LOGLEVEL]
-n INTERFACENAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --interfacename INTERFACENAME
Required

The Lightning interface name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningIntf
Default value: DefaultLightningIntf
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string

force:lightning:lwc:test:create

Creates a __tests__ directory in the specified directory. Creates a yourComponentName.test.js file with boilerplate code in the __tests__ directory.

Examples for force:lightning:lwc:test:create

1$ sfdx force:lightning:lwc:test:create -f force-app/main/default/lwc/myButton/myButton.js

Command Syntax

sfdx force:lightning:lwc:test:create
[--json]
[--loglevel LOGLEVEL]
-f FILEPATH

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-f | --filepath FILEPATH
Required

Path to Lightning web component .js file to create a test for.

Type: string

force:lightning:lwc:test:run

Invokes Lightning Web Components Jest unit tests.

Examples for force:lightning:lwc:test:run

1$ sfdx force:lightning:lwc:test:run
1$ sfdx force:lightning:lwc:test:run -w

Command Syntax

sfdx force:lightning:lwc:test:run
[--json]
[--loglevel LOGLEVEL]
[-d]
[--watch]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-d | --debug
Optional

Runs tests in a Node process that an external debugger can connect to. The run pauses until the debugger is connected. For more information, see: https://jestjs.io/docs/en/troubleshooting

Type: boolean
--watch
Optional

Runs tests when a watched file changes. Watched files include the component under test and any files it references.

Type: boolean

force:lightning:lwc:test:setup

Installs Jest unit testing tools for Lightning Web Components. For more information, see the Lightning Web Components Dev Guide: https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.testing.

Examples for force:lightning:lwc:test:setup

1$ sfdx force:lightning:lwc:test:setup

Command Syntax

sfdx force:lightning:lwc:test:setup
[--json]
[--loglevel LOGLEVEL]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn

force:lightning:test:create

Creates a Lightning test in the specified directory or the current working directory. The .resource file and associated metadata file are created.

Help for force:lightning:test:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

Examples:

1$ sfdx force:lightning:test:create -n MyLightningTest
1$ sfdx force:lightning:test:create -n MyLightningTest -d lightningTests

Command Syntax

sfdx force:lightning:test:create
[--json]
[--loglevel LOGLEVEL]
-n TESTNAME
[-t TEMPLATE]
[-d OUTPUTDIR]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --testname TESTNAME
Required

The name of the new Lightning test. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningTest
Default value: DefaultLightningTest
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .