Azure Static Web Apps with Vue.js and Visual Studio Code
Tags: azure, vue, visualstudiocode, staticwebapps
Published: 2023-02-11 18:24:14

Hey everyone, in today's post we are talking about how deploy an Vue.js Application to Azure Static Web App using Visual Studio Code.

To understand what is Azure Static Web App, visit [Azure Static Web Apps - The Big Picture](https://dev.to/reniciuspagotto/azure-static-web-apps-the-big-picture-1e16)

## Prerequisites
- [NPM](https://nodejs.org/en/download)
- [Vue CLI](https://cli.vuejs.org/guide/installation.html)
- [Visual Studio Code](https://code.visualstudio.com/)
- [Azure Static Web App extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurestaticwebapps) for Visual Studio Code
- [Git](https://git-scm.com)

## Implementation
Once you have all the prerequisites installed, let's create the project itself. For that, let's use the command line and run the command below to create a Vue.js project.

`vue create <vue-project-name>`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gumgq7f61qxb8cs5tiqh.png)

After creating the project, let's open it in Visual Studio Code. You can open the project using the interface or by typing the command below in your command line tool.

`code .`

**Important:** Always access the project root before opening in Visual Studio Code or you can open VS Code first and then open the project root. Always avoid opening in the folder before the project as this can lead to errors in the build and consequently in the pipeline.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66lqaf3g3wy8y9uwh8vc.png)

The next step is the deployment, so Press F1 and search for Azure Static Web App: Create Static Web Apps and select.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7kiencvmuqrr0bwmsht.png)

In the next step, we need to select the Azure Subscription, but if you are not logged into your Azure account with Visual Studio Code, an option to make the connection will be displayed.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqzf631ctsp8rcqrogtm.png)

In the next option, we need to define the name to be given to the service in Azure.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ypo0fc7rf8plc3xpes8.png)

Now, we need to define a name for the GitHub Repository

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4bjc9cvslamcpd7baro.png)

The next step is to define the region where the resource will be created.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mtn36mnhnqg6w5d3pa1.png)

Now it's time to define the project type. Note that Azure Static Web Apps supports multiple frameworks and since our project is a Vue.js project, we should select the Vue option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/but31qq8xnnlj40sfb0a.png)

Here we need to set the path to the root of the Vue project. By doing this, the executor responsible for deploying the code will be able to run the _npm run build_ command to generate the outputs in the _dist_ directory. Let's set / to this option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p10w6x34x755z0n2fg7e.png)

In the last step, we need to define the application build output path and for Vue.js projects we need to inform the _dist_ folder.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zi2s37czzk571xkhx0g3.png)

Finally, press enter to start creating the resource on Azure and creating the repository on GitHub.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aoz0qc60hxtdey2r246l.png)

Once the run is complete, we have an instance of Azure Static Web Apps provisioned in Azure and ready to use, and the repository on GitHub with our code. At the end, the code deployment pipeline will be executed automatically by GitHub Actions.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omlem2h6u3srg2um6el2.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9j76kqqfd6f8t9wpdh24.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x2k9zwx8rjjc599gyloj.png)

Now, let's open the Azure Portal to get the link of our the Web Site in Azure Static Web App resource.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1orz528yxfrxozrgv45.png)

With the link copied, paste it into your browser to see the result or you can simply click on the link to be redirected automatically.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zmbi15ne8gq6bkoxx8f.png)

## Conclusion
Azure Static Web Apps is a powerful feature that makes it easy and fast to build and deliver a modern front-end project.

Did you like this post? Want to talk a little more about it? Leave a comment with your questions and ideas or get in touch through [LinkedIn](https://www.linkedin.com/in/renicius-pagotto).