Configuring CLI
Version
Updated for Azure Static Web Apps CLI (1.0.0-preview)
Configuration
The SWA CLI gets configuration information for your Azure Static Web Apps in one of two ways:
- from CLI options (passed in at runtime)
- from a CLI configuration file (created and stored in project)
By default, the SWA CLI looks for a configuration file called swa-cli.config.json
in the current directory.
Configuration File:
The configuration file can contain multiple configurations (e.g., one per project), each identified by a unique configuration name.
- If only a single configuration is present in the
swa-cli.config.json
file, runningswa start
will use it by default. - If options are loaded from a config file, no options passed in via command line will be respected. For example if we use
swa start app --ssl=true
, thessl=true
option will not be picked up by the CLI.
Configuration File Example:
{
"configurations": {
"app": {
"outputLocation": "http://localhost:3000",
"apiLocation": "api",
"run": "npm run start",
"swaConfigLocation": "./my-app-source"
}
}
}
View Configuration
The Static Webs CLI provides a --print-config
option that you can use to determine resolved options for your current setup.
Here is an example of what that output looks like when run on a new project (i.e., shows default settings)
swa --print-config
Welcome to Azure Static Web Apps CLI (1.0.0-preview)
Options:
- port: 4280
- host: localhost
- apiPort: 7071
- appLocation: .
- apiLocation: <undefined>
- outputLocation: .
- swaConfigLocation: <undefined>
- ssl: false
- sslCert: <undefined>
- sslKey: <undefined>
- appBuildCommand: <undefined>
- apiBuildCommand: <undefined>
- run: <undefined>
- verbose: log
- serverTimeout: 60
- open: false
- githubActionWorkflowLocation: <undefined>
- env: preview
- appName: <undefined>
- dryRun: false
- subscriptionId: <undefined>
- resourceGroupName: <undefined>
- tenantId: <undefined>
- clientId: <undefined>
- clientSecret: <undefined>
- useKeychain: true
- clearCredentials: false
- config: swa-cli.config.json
- printConfig: true
Running swa --print-config
will provide the current configuration defaults - if the project has not yet defined a configuration file, this will automatically trigger the swa init
workflow to help you create one.
Init Configuration
Use swa init
to kickstart the workflow to create a configuration file for a new or existing project. If the project exists, swa init
will try to make educated guesses on the configuration settings for you, with ability to override it during creation.
By default the process creates these settings in a swa-cli.config.json
in the current working directory of your project. This is the default file name/location used by swa
when searching for project configuration info.
swa --config <path>
If the file contains only one named configuration, it is used by default. If multiple configurations are defined, specify the one to use at commandline
swa --config-name
When the configuration file option is used, the settings are stored in JSON format. Once created, you can manually edit the file to update settings (if preferred) or use swa init
to make updates.