Skip to content

Commit b5f6e12

Browse files
authored
Update static-web-apps-cli.md
1 parent 9f99a27 commit b5f6e12

File tree

1 file changed

+202
-1
lines changed

1 file changed

+202
-1
lines changed

articles/static-web-apps/static-web-apps-cli.md

Lines changed: 202 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
description: Azure Static Web Apps CLI reference
23
title: Azure Static Web Apps CLI reference
34
ms.topic: reference
45
ms.date: 07/25/2025
@@ -114,6 +115,16 @@ The following is an example configuration generated by the `init` command:
114115
```json
115116
{
116117
"$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
118+
"configurations": {
119+
"myApp": {
120+
"appLocation": ".",
121+
"apiLocation": "api",
122+
"outputLocation": "dist",
123+
"appBuildCommand": "npm run build",
124+
"apiBuildCommand": "npm run build --if-present",
125+
"run": "npm run dev",
126+
"appDevserverUrl": "http://localhost:8080"
127+
}
117128
}
118129
}
119130
```
@@ -164,6 +175,10 @@ Common use cases include: installing dependencies for the front-end app and API
164175
```azstatic-cli
165176
swa build
166177
[--app-location]
178+
[--api-location]
179+
[--output-location]
180+
[--app-build-command]
181+
[--api-build-command]
167182
[--auto]
168183
```
169184

@@ -229,8 +244,16 @@ Start the Azure Static Web Apps emulator from a directory or bind to a running d
229244

230245
By default, the CLI starts and serves any static content from the current working directory `./`:
231246

247+
```azstatic-cli
248+
swa start
249+
```
250+
232251
If the artifact folder of your static app is under a different folder (for example, `./my-dist`), then run the CLI and provide that folder:
233252

253+
```azstatic-cli
254+
swa start ./my-dist
255+
```
256+
234257
### Serve from a dev server
235258

236259
When developing your front-end app locally, it's often useful to use the dev server that comes with your front end framework's CLI. Using the framework CLI allows you to use built-in features like "livereload" and HMR (hot module replacement).
@@ -241,12 +264,39 @@ To use SWA CLI with your local dev server, follow these two steps:
241264

242265
1. In a separate terminal, run `swa start` with the URI provided by the dev server, in the following format:
243266

267+
```azstatic-cli
268+
swa start http://<APP_DEV_SERVER_HOST>:<APP_DEV_SERVER_PORT>
269+
```
270+
244271
Here is a list of the default ports and commands used by some popular dev servers:
245272

273+
| Tool | Port | Command |
274+
|--|--|--|
275+
| [Angular](https://angular.io/cli) | `4200` | `swa start http://localhost:4200` |
276+
| [Blazor WebAssembly](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) | `5000` | `swa start http://localhost:5000` |
277+
| [Gatsby](https://www.gatsbyjs.com/docs/reference/gatsby-cli/) | `8000` | `swa start http://localhost:8000` |
278+
| [Hugo](https://gohugo.io/commands/hugo_server/) | `1313` | `swa start http://localhost:1313` |
279+
| [Next.js](https://nextjs.org/) | `3000` | `swa start http://localhost:3000` |
280+
| [React (Create React App)](https://reactjs.org/docs/create-a-new-react-app.html) | `3000` | `swa start http://localhost:3000` |
281+
| [Svelte (sirv-cli)](https://github.com/lukeed/sirv/tree/master/packages/sirv-cli/) | `5000` | `swa start http://localhost:5000` |
246282
| [Vue](https://github.com/vuejs/create-vue) | `3000` | `swa start http://localhost:3000` |
247283

248284
Instead of starting a dev server separately, you can provide the startup command to the CLI.
249285

286+
```azstatic-cli
287+
# npm start script (React)
288+
swa start http://localhost:3000 --run "npm start"
289+
290+
# dotnet watch (Blazor)
291+
swa start http://localhost:5000 --run "dotnet watch run"
292+
293+
# Jekyll
294+
swa start http://localhost:4000 --run "jekyll serve"
295+
296+
# custom script
297+
swa start http://localhost:4200 --run "./startup.sh"
298+
```
299+
250300
Then access the application with the emulated services from `http://localhost:4280`
251301

252302
### Serve both the front-end app and API
@@ -257,6 +307,14 @@ If your project includes API functions, the CLI will check if the Azure Function
257307

258308
Run the CLI and provide the folder that contains the API backend (a valid Azure Functions App project):
259309

310+
```azstatic-cli
311+
# static content plus an API
312+
swa start ./my-dist --api-location ./api
313+
314+
# front-end dev server plus an API
315+
swa start http://localhost:3000 --api-location ./api
316+
```
317+
260318
#### Start API server manually
261319

262320
When developing your backend locally, sometimes it's useful to run Azure Functions Core Tools separately to serve your API. This allows you to use built-in features like debugging and rich editor support.
@@ -267,9 +325,17 @@ To use the CLI with your local API backend dev server, follow these two steps:
267325

268326
2. In a separate terminal, run the SWA CLI with the `--api-location` flag and the URI of the local API server, in the following format:
269327

328+
```azstatic-cli
329+
swa start ./my-dist --api-location http://localhost:7071
330+
```
331+
270332
#### Database connections
271333

272-
To start your application with a [database connection](database-overview.md), use the `--data-api-location` parameter and point to the folder containing the *staticwebapp.database.config.json* file.
334+
To start your application with a [database connection](database-overview.md), use the `--data-api-location` parameter and point to the folder containing the _staticwebapp.database.config.json_ file.
335+
336+
```azstatic-cli
337+
swa start ./src --data-api-location swa-db-connections
338+
```
273339

274340
### Syntax
275341

@@ -389,8 +455,18 @@ The SWA CLI supports deploying using a deployment token. This is often useful wh
389455

390456
- If you are using the [Azure CLI](https://aka.ms/azcli), you can get the deployment token of your project using the following command:
391457

458+
```azstatic-cli
459+
az staticwebapp secrets list --name <APPLICATION_NAME> --query "properties.apiKey"
460+
```
461+
392462
- If you are using the Azure Static Web Apps CLI, you can use the following command:
393463

464+
```azstatic-cli
465+
swa deploy --print-token
466+
```
467+
468+
You can then use that value with the `--deployment-token <TOKEN>` or you can create an environment variable called `SWA_CLI_DEPLOYMENT_TOKEN` and set it to the deployment token.
469+
394470
> **Important**: Don't store the deployment token in a public repository. This value must remain a secret.
395471
396472
### Deploy a front end app without an API
@@ -401,6 +477,11 @@ You can deploy a front end application without an API to Azure Static Web Apps b
401477

402478
**Option 1:** From build folder you would like to deploy, run the deploy command:
403479

480+
```azstatic-cli
481+
cd build/
482+
swa deploy
483+
```
484+
404485
> **Note**: The `build` folder must contain the static content of your app that you want to deploy.
405486
406487
**Option 2:** You can also deploy a specific folder:
@@ -409,14 +490,102 @@ You can deploy a front end application without an API to Azure Static Web Apps b
409490

410491
2. Deploy your app:
411492

493+
```azstatic-cli
494+
swa deploy ./my-dist
495+
```
496+
412497
### Deploy a front-end app with an API
413498

414499
To deploy both the front end app and an API to Azure Static Web Apps, use the following steps:
415500

501+
1. If your front end application requires a build step, run `swa build` or refer to your application build instructions.
502+
503+
2. Make sure the API language runtime version in the `staticwebapp.config.json` file is set correctly, for example:
504+
505+
```json
506+
{
507+
"platform": {
508+
"apiRuntime": "node:16"
509+
}
510+
}
511+
```
512+
513+
> **Note**: If your project doesn't have any `staticwebapp.config.json` file, add one under your `outputLocation` folder.
514+
515+
3. Deploy your app:
516+
517+
```azstatic-cli
518+
swa deploy ./my-dist --api-location ./api
519+
```
520+
521+
### Deploy a Blazor app
522+
523+
To deploy a Blazor app with an optional API to Azure Static Web Apps, use the following steps:
524+
525+
1. Build your Blazor app in **Release** mode:
526+
527+
```azstatic-cli
528+
dotnet publish -c Release -o bin/publish
529+
```
530+
531+
2. From the root of your project, run the `deploy` command:
532+
533+
```azstatic-cli
534+
swa deploy ./bin/publish/wwwroot --api-location ./Api
535+
```
536+
537+
### Deploy using the `swa-cli.config.json`
538+
539+
> **Note**: The path for `outputLocation` must be relative to the `appLocation`.
540+
541+
If you are using a `swa-cli.config.json` configuration file in your project and have a single configuration entry, use a configuration like this:
542+
543+
```json
544+
{
545+
"configurations": {
546+
"my-app": {
547+
"appLocation": "./",
548+
"apiLocation": "api",
549+
"outputLocation": "frontend",
550+
"start": {
551+
"outputLocation": "frontend"
552+
},
553+
"deploy": {
554+
"outputLocation": "frontend"
555+
}
556+
}
557+
}
558+
}
559+
```
560+
561+
Then you can deploy your application by running the following steps:
562+
563+
1. If your front-end application requires a build step, run `swa build` or refer to your application build instructions.
564+
565+
2. Deploy your app:
566+
567+
```azstatic-cli
568+
swa deploy
569+
```
570+
571+
If you have multiple configuration entries, you can provide the entry ID to specify which one to use:
572+
573+
```azstatic-cli
574+
swa deploy my-otherapp
575+
```
576+
416577
### Syntax
417578

418579
```azstatic-cli
419580
swa deploy
581+
[--api-location]
582+
[--app-location]
583+
[--output-location]
584+
[--deployment-token]
585+
[--env]
586+
[--print-token]
587+
[--data-api-location]
588+
[--swa-config-location]
420589
```
421590

422591
### Examples
@@ -453,6 +622,38 @@ swa deploy --env production
453622

454623
### Parameters
455624

625+
___`--app-location, -a <PATH>`___
626+
627+
The folder containing the source code of the front-end application. Default is `.`.
628+
629+
___`--api-location, -i <PATH>`___
630+
631+
The folder containing the source code of the API application.
632+
633+
___`--output-location, -O <PATH>`___
634+
635+
The folder containing the built source of the front-end application. The path is relative to `--app-location`. Default is `.`.
636+
637+
___`--deployment-token, -t <TOKEN>`___
638+
639+
Secret token used to authenticate with the Azure Static Web Apps service.
640+
641+
___`--env, -e <ENVIRONMENT_NAME>`___
642+
643+
Named environment that you want to deploy to.
644+
645+
___`--print-token`___
646+
647+
Print the deployment token for the Static Web Apps resource.
648+
649+
___`--data-api-location, -d <PATH>`___
650+
651+
The folder containing the database configuration file.
652+
653+
___`--swa-config-location, -w <PATH>`___
654+
655+
The path to the directory containing the staticwebapp.config.json file used for the deployment.
656+
456657
___[Global Parameters](#global-parameters)___
457658

458659
## swa db

0 commit comments

Comments
 (0)