Azure Static Web Apps CLI (swa) - Deploy to Azure


The Azure Static Web Apps CLI (swa) is a command-line tool that helps you develop, test, and deploy static web apps to Azure Static Web Apps.



Key Features:

Local development: Emulates Azure environment locally (swa start)

Mock backend API support: Connects frontend to Azure Functions or mock APIs

Easy deployment: Deploys to Azure with a single command (swa deploy)

Supports popular frameworks: Works with React, Angular, Vue, Vite, Svelte, etc.

Global Installation (Recommended for CLI use)


npm install -g @azure/static-web-apps-cli


yarn global add @azure/static-web-apps-cli


Serve a built static site locally 

yarn build   # or npm run build
swa start ./dist

start: Starts the local development server

./dist: The path to your built static files (e.g., Vite or React build output)

  • Serves the contents of the ./dist directory at http://localhost:4280 by default
  • Mimics Azure Static Web Apps behavior
  • Handles routing, authentication, and API integration (if configured)
  • Automatically sets up navigation fallback (so client-side routing like React Router works properly)

Deployment token


The SWA CLI supports deploying using a deployment token to enable setups in CI/CD environments.


You can get a deployment token from:


Azure portal: Home → Static Web App → Your Instance → Overview → Manage deployment token


Use It with the CLI


swa deploy ./build --env production --deployment-token <your-token>


Replace ./build with your actual output directory (like ./dist for Vite).


No comments:

Theme images by merrymoonmary. Powered by Blogger.