You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/static-web-apps/deploy-nuxtjs.md
+15-81Lines changed: 15 additions & 81 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,16 +24,15 @@ In this tutorial, you learn to deploy a [Nuxt 3](https://v3.nuxtjs.org/) applica
24
24
25
25
You can set up a new Nuxt project using `npx nuxi init nuxt-app`. Instead of using a new project, this tutorial uses an existing repository set up to demonstrate how to deploy a Nuxt 3 site with universal rendering on Azure Static Web Apps.
26
26
27
-
1. Create a new repository under your GitHub account from a template repository.
28
-
1. Go to [http://github.com/staticwebdev/nuxt-3-starter/generate](https://github.com/login?return_to=/staticwebdev/nuxt-3-starter/generate)
27
+
1. Navigate to [http://github.com/staticwebdev/nuxt-3-starter/generate](https://github.com/login?return_to=/staticwebdev/nuxt-3-starter/generate).
29
28
1. Name the repository **nuxt-3-starter**.
30
29
1. Next, clone the new repo to your machine. Make sure to replace <YOUR_GITHUB_ACCOUNT_NAME> with your account name.
@@ -51,47 +50,17 @@ You can set up a new Nuxt project using `npx nuxi init nuxt-app`. Instead of usi
51
50
npm run dev -- -o
52
51
```
53
52
54
-
Go to `http://localhost:3000` to open the app, where you should see the following website open in your preferred browser:
53
+
Navigate to `http://localhost:3000` to open the app, where you should see the following website open in your preferred browser. Select the buttons to invoke server and API routes.
When you build a Nuxt.js site using `npm run build`, the app is built as a traditional web app, not a static site. To generate a static site, use the following application configuration.
65
-
66
-
1. Update the _package.json_'s build script to only generate a static site using the `nuxt generate` command:
67
-
68
-
```json
69
-
"scripts": {
70
-
"dev": "nuxt dev",
71
-
"build": "nuxt generate"
72
-
},
73
-
```
74
-
75
-
Now with this command in place, Static Web Apps runs the `build` script every time you push a commit.
76
-
77
-
2. Generate a static site:
78
-
79
-
```bash
80
-
npm run build
81
-
```
82
-
83
-
Nuxt.js generates the static site and copy it into a _dist_ folder at the root of your working directory.
84
-
85
-
> [!NOTE]
86
-
> This folder is listed in the _.gitignore_ file because it should be generated by CI/CD when you deploy.
87
-
88
-
## Deploy your static website
89
-
90
-
The following steps show how to link the app you just pushed to GitHub to Azure Static Web Apps. Once in Azure, you can deploy the application to a production environment.
59
+
The following steps show how to create an Azure Static Web Apps resource and configure it to deploy your app from GitHub.
91
60
92
61
### Create an Azure Static Web Apps resource
93
62
94
-
1. Go to the [Azure portal](https://portal.azure.com).
63
+
1. Navigate to the [Azure portal](https://portal.azure.com).
95
64
1. Select **Create a Resource**.
96
65
1. Search for**Static Web Apps**.
97
66
1. Select **Static Web Apps**.
@@ -127,13 +96,13 @@ The following steps show how to link the app you just pushed to GitHub to Azure
127
96
128
97
1. Select **Review + Create** to verify the details are all correct.
129
98
130
-
2. Select **Create** to start the creation of the App Service Static Web App and provision a GitHub Actions for deployment.
99
+
1. Select **Create** to start the creation of the static web app and provision a GitHub Actions for deployment.
131
100
132
-
3. Once the deployment completes, select **Go to resource**.
101
+
1. Once the deployment completes, select**Go to resource**.
133
102
134
-
4. On the _Overview_ window, select the *URL* link to open your deployed application.
103
+
1. On the _Overview_ window, selectthe*URL* link to open your deployed application.
135
104
136
-
If the website does note immediately load, then the background GitHub Actions workflow is still running. Once the workflow is complete you can then select refresh the browser to view your web app.
105
+
If the website does not immediately load, then the background GitHub Actions workflow is still running. Once the workflow is complete you can then refresh the browser to view your web app.
137
106
138
107
You can check the status of the Actions workflows by navigating to the Actions for your repository:
When you created the app, Azure Static Web Apps created a GitHub Actions workflow file in your repository. Return to the terminal and run the following command `git pull origin main` to pull the commit containing the new file.
147
-
148
-
## Configure dynamic routes
115
+
When you created the app, Azure Static Web Apps created a GitHub Actions workflow file in your repository. Return to the terminal and run the following command to pull the commit containing the new file.
149
116
150
-
Go to the newly-deployed site and select one of the framework or library logos. Instead of getting a details page, you get a 404 error page.
151
-
152
-
:::image type="content" source="media/deploy-nuxtjs/404-in-production.png" alt-text="404 on dynamic routes":::
153
-
154
-
The reason for this is, Nuxt.js generated the static site, it only did so for the home page. Nuxt.js can generate equivalent static `.html` files for every `.vue` pages file, but there's an exception.
155
-
156
-
If the page is a dynamic page, for example `_id.vue`, it won't have enough information to generate a static HTML from such dynamic page. You'll have to explicitly provide the possible paths for the dynamic routes.
157
-
158
-
## Generate static pages from dynamic routes
159
-
160
-
1. Update the _nuxt.config.js_ file so that Nuxt.js uses a list of all available data to generate static pages for each framework/library:
161
-
162
-
```javascript
163
-
import { projects } from "./utils/projectsData";
164
-
165
-
export default {
166
-
mode: "universal",
167
-
168
-
//...truncated
169
-
170
-
generate: {
171
-
async routes() {
172
-
const paths = [];
173
-
174
-
projects.forEach(project => {
175
-
paths.push(`/project/${project.slug}`);
176
-
});
177
-
178
-
return paths;
179
-
}
180
-
}
181
-
};
182
-
```
183
-
184
-
> [!NOTE]
185
-
>`routes` is an async function, so you can make a request to an API in this functionand use the returned list to generate the paths.
117
+
```bash
118
+
git pull
119
+
```
186
120
187
121
Make changes to the app by updating the code and pushing it to GitHub. GitHub Actions automatically builds and deploys the app.
188
122
189
-
For more information, see the Azure Static Web Apps Nuxt 3 deployment preset [documentation](https://nitro.unjs.io/deploy/providers/azure).
123
+
For more information, see the Azure Static Web Apps Nuxt 3 deployment preset [documentation](https://nitro.unjs.io/deploy/providers/azure#azure-static-web-apps).
0 commit comments