Problem
When creating Azure Static Web App in Azure portal. The deployment options did not provide clear instructions for how to deploy without creating a project and CI/CD pipeline on GitHub or Azure DevOps. Many times, we just want to deploy a simple one-time project from local computer. Let's see how to do this.
Solution
Install SWA CLI Tool
We need to use Microsoft official tool "Static Web Apps CLI" to deploy from local machine. First, install it from npm.
npm install -g @azure/static-web-apps-cli
Build Your App
This step is only required when you are using a front-end framework that requires build, such as Angular.
In my case, I am using Angular. I run "ng build
" and generate the website content files in ./dist/test996. This is the folder to deploy to Azure Static Web App.
Now, inside `dist` folder. Open a terminal and run:
swa deploy ./test996 --env production
SWA CLI will let you login to Azure, then choose or create the target instance of Azure Static Web App, then zip the website folder and upload to Azure.
After it is done, we can browse the website in a second.
Bug or feature?
There seems to be a bug that you cannot deploy the current directory to Azure Static Web App. It won't throw errors, but your website will have empty content deployed. So, we must specify a directory for now.
For example, you have your index.html and other stuff inside `C:\your-project`.
DO NOT use this
C:\your-project\> swa deploy
Move your files to "build" folder and use this
C:\your-project\> swa deploy ./build
Nikolay
Thank you, my friend. The fact it does not work with the current directory is something I could not guess. You saved my day.
Jana
Great. Searched hours for the reason of the pending deployment. You made my day.
Sandy
I got this error while deploying using swa -
Checking Azure session... ✖ this.keychainCache.findCredentials is not a function
SJ
Thank you, great help. I was missing this - Note: the "build" folder must contain the static content of your app to be deployed!
DE
Just FYI, I got the error below because I have never run the command 'az login'
Checking Azure session... ✖ this.keychainCache.findCredentials is not a function