|
| 1 | +--- |
| 2 | +title: Deploy your web app to Azure Static Web Apps. |
| 3 | +description: Learn to deploy your web app to Azure Static Web Apps. |
| 4 | +services: static-web-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: static-web-apps |
| 7 | +ms.topic: article |
| 8 | +ms.date: 07/02/2024 |
| 9 | +ms.author: cshoe |
| 10 | +zone_pivot_groups: swa-web-framework |
| 11 | +--- |
| 12 | + |
| 13 | +# Deploy your web app to Azure Static Web Apps |
| 14 | + |
| 15 | +In this article, you create a new web app with the framework of your choice, run it locally, then deploy to Azure Static Web Apps. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +To complete this tutorial, you need: |
| 20 | + |
| 21 | +| Resource | Description | |
| 22 | +|---|---| |
| 23 | +| [Azure subscription][1] | If you don't have one, you can [create an account for free][1]. | |
| 24 | +| [Node.js][2] | Install version 20.0 or later. | |
| 25 | +| [Azure CLI][3] | Install version 2.6x or later. | |
| 26 | + |
| 27 | +You also need a text editor. For work with Azure, [Visual Studio Code][4] is recommended. |
| 28 | + |
| 29 | +You can run the app you create in this article on the platform of your choice including: Linux, macOS, Windows, or Windows Subsystem for Linux. |
| 30 | + |
| 31 | +## Create your web app |
| 32 | + |
| 33 | +1. Open a terminal window. |
| 34 | + |
| 35 | +::: zone pivot="vanilla-js" |
| 36 | + |
| 37 | +2. Select an appropriate directory for your code, then run the following commands. |
| 38 | + |
| 39 | + ```bash |
| 40 | + npm create vite@latest swa-vanilla-demo -- --template=vanilla |
| 41 | + cd swa-vanilla-demo |
| 42 | + npm install |
| 43 | + npm run dev |
| 44 | + ``` |
| 45 | + |
| 46 | + As you run these commands, the development server prints the URL of your website. Select the link to open it in your default browser. |
| 47 | + |
| 48 | + ![Screen shot of the generated vanilla web application.][img-vanilla-js] |
| 49 | + |
| 50 | +::: zone-end |
| 51 | + |
| 52 | +::: zone pivot="angular" |
| 53 | + |
| 54 | +2. Select an appropriate directory for your code, then run the following commands. |
| 55 | + |
| 56 | + ```bash |
| 57 | + npx --package @angular/cli@latest ng new swa-angular-demo --ssr=false --defaults |
| 58 | + cd swa-angular-demo |
| 59 | + npm start |
| 60 | + ``` |
| 61 | + |
| 62 | + As you run these commands, the development server prints the URL of your website. Select the link to open it in your default browser. |
| 63 | + |
| 64 | + ![Screen shot of the generated angular web application.][img-angular] |
| 65 | + |
| 66 | +::: zone-end |
| 67 | + |
| 68 | +::: zone pivot="react" |
| 69 | + |
| 70 | +2. Select an appropriate directory for your code, then run the following commands. |
| 71 | + |
| 72 | + ```bash |
| 73 | + npm create vite@latest swa-react-demo -- --template react |
| 74 | + cd swa-react-demo |
| 75 | + npm install |
| 76 | + npm run dev |
| 77 | + ``` |
| 78 | + |
| 79 | + As you run these commands, the development server prints the URL of your website. Select the link to open it in your default browser. |
| 80 | + |
| 81 | + ![Screen shot of the generated react web application.][img-react] |
| 82 | + |
| 83 | +::: zone-end |
| 84 | + |
| 85 | +::: zone pivot="vue" |
| 86 | + |
| 87 | +2. Select an appropriate directory for your code, then run the following commands. |
| 88 | + |
| 89 | + ```bash |
| 90 | + npm create vite@latest swa-vue-demo -- --template vue |
| 91 | + cd swa-vue-demo |
| 92 | + npm install |
| 93 | + npm run dev |
| 94 | + ``` |
| 95 | + |
| 96 | + As you run these commands, the development server prints the URL of your website. Select the link to open it in your default browser. |
| 97 | + |
| 98 | + ![Screen shot of the generated Vue web application.][img-vue] |
| 99 | + |
| 100 | +::: zone-end |
| 101 | + |
| 102 | +3. Select <kbd>Cmd/Ctrl</kbd>+<kbd>C</kbd> to stop the development server. |
| 103 | + |
| 104 | +[!INCLUDE [Create an Azure Static Web App](../../includes/static-web-apps/quickstart-direct-deploy-create.md)] |
| 105 | + |
| 106 | +[!INCLUDE [Build your site for deployment](../../includes/static-web-apps/quickstart-direct-deploy-build.md)] |
| 107 | + |
| 108 | +::: zone pivot="angular" |
| 109 | + |
| 110 | +> [!WARNING] |
| 111 | +> Angular v17 and later place the distributable files in a subdirectory of the output path that you can choose. The SWA CLI doesn't know the specific location of the directory. The following steps show you how to set this path correctly. |
| 112 | +
|
| 113 | +Locate the generated *index.html* file in your project in the *dist/swa-angular-demo/browser* folder. |
| 114 | +
|
| 115 | +1. Set the `SWA_CLI_OUTPUT_LOCATION` environment variable to the directory containing the *index.html* file: |
| 116 | +
|
| 117 | + # [bash](#tab/bash) |
| 118 | +
|
| 119 | + ```bash |
| 120 | + export SWA_CLI_OUTPUT_LOCATION="dist/swa-angular-demo/browser" |
| 121 | + ``` |
| 122 | +
|
| 123 | + # [csh](#tab/csh) |
| 124 | +
|
| 125 | + ```bash |
| 126 | + setenv SWA_CLI_OUTPUT_LOCATION "dist/swa-angular-demo/browser" |
| 127 | + ``` |
| 128 | +
|
| 129 | + # [PowerShell](#tab/pwsh) |
| 130 | +
|
| 131 | + ```powershell |
| 132 | + $env:SWA_CLI_OUTPUT_LOCATION="dist/swa-angular-demo/browser" |
| 133 | + ``` |
| 134 | +
|
| 135 | + # [CMD](#tab/cmd) |
| 136 | +
|
| 137 | + ```bash |
| 138 | + set SWA_CLI_OUTPUT_LOCATION="dist/swa-angular-demo/browser" |
| 139 | + ``` |
| 140 | +
|
| 141 | + --- |
| 142 | +
|
| 143 | +::: zone-end |
| 144 | +
|
| 145 | +## Deploy your site to Azure |
| 146 | +
|
| 147 | +Deploy your code to your static web app: |
| 148 | +
|
| 149 | +```bash |
| 150 | +npx swa deploy --env production |
| 151 | +``` |
| 152 | +
|
| 153 | +It might take a few minutes to deploy the application. Once complete, the URL of your site is displayed. |
| 154 | +
|
| 155 | +![Screen shot of the deploy command.][img-deploy] |
| 156 | +
|
| 157 | +On most systems, you can select the URL of the site to open it in your default browser. |
| 158 | +
|
| 159 | +[!INCLUDE [Clean up resources](../../includes/static-web-apps/quickstart-direct-deploy-clean-up-resources.md)] |
| 160 | +
|
| 161 | +## Next steps |
| 162 | +
|
| 163 | +> [!div class="nextstepaction"] |
| 164 | +> [Add authentication](./add-authentication.md) |
| 165 | +
|
| 166 | +## Related content |
| 167 | +
|
| 168 | +* [Authentication and authorization](./authentication-authorization.yml) |
| 169 | +* [Database connections](./database-overview.md) |
| 170 | +* [Custom Domains](./custom-domain.md) |
| 171 | +
|
| 172 | +<!-- Links --> |
| 173 | +[1]: https://azure.microsoft.com/free |
| 174 | +[2]: https://nodejs.org/ |
| 175 | +[3]: /cli/azure/install-azure-cli |
| 176 | +[4]: https://code.visualstudio.com |
| 177 | +
|
| 178 | +<!-- Images --> |
| 179 | +[img-deploy]: media/deploy-screenshot.png |
| 180 | +[img-vanilla-js]: media/deploy-web-framework/vanilla-js-screenshot.png |
| 181 | +[img-angular]: media/deploy-web-framework/angular-screenshot.png |
| 182 | +[img-react]: media/deploy-web-framework/react-screenshot.png |
| 183 | +[img-vue]: media/deploy-web-framework/vue-screenshot.png |
0 commit comments