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-apps/deploy-nextjs.md
+39-45Lines changed: 39 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,16 +24,19 @@ In this tutorial, you learn to deploy a [Next.js](https://nextjs.org) generated
24
24
25
25
Rather than using the Next.js CLI to create an app, you can use a starter repository that includes an existing Next.js app. This repository features a Next.js app with dynamic routes, which highlights a common deployment issue. Dynamic routes need an extra deployment configuration which you will learn more about in a moment.
26
26
27
-
1. Clone starter repository:
27
+
1. Create a new repository under your GitHub account from a template repository.
28
+
1. Navigate to <http://github.com/staticwebdev/nextjs-starter/generate>
29
+
1. Name the repository **nextjs-starter**
30
+
1. Next, clone the new repo to your machine. Make sure to replace <YOUR_GITHUB_ACCOUNT_NAME> with your account name.
@@ -60,7 +63,7 @@ When you click on a framework/library, you should see a details page about the s
60
63
61
64
When you build a Next.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.
62
65
63
-
1. To configure static routes, create file named _next.config.js_ at the root of your project.
66
+
1. To configure static routes, create file named _next.config.js_ at the root of your project and add the following code..
64
67
65
68
```javascript
66
69
module.exports = {
@@ -99,53 +102,41 @@ When you build a Next.js site using `npm run build`, the app is built as a tradi
99
102
100
103
## Push your static website to GitHub
101
104
102
-
Azure Static Web Apps deploys your app from a GitHub repository and keeps doing so for every pushed commit to a designated branch. Use the following command to set up a repository.
103
-
104
-
1. Initialize a git repo
105
+
Azure Static Web Apps deploys your app from a GitHub repository and keeps doing so for every pushed commit to a designated branch. Use the following commands sync your changes to GitHub.
105
106
107
+
1. Stage all changed files
106
108
```bash
107
-
# Remove existing .git
108
-
rm -rf .git
109
-
# Initialize git
110
-
git init
111
-
# Add all files
112
109
git add .
113
-
# Commit changes
114
-
git commit -m "initial commit"
115
110
```
116
-
117
-
1. Create a blank GitHub repo (don't create a README) from [https://github.com/new](https://github.com/new) and name it whatever you like for example, **nextjs-static-website**.
118
-
119
-
1. Add the GitHub repo as a remote to your local repo.
The following steps show how to deploy the app you just pushed to GitHub to Azure Static Web Apps. Once in Azure you can deploy the application to a production environment.
124
+
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.
134
125
135
126
### Create Azure App Service Static App
136
127
137
128
1. Navigate to the [Azure Portal](https://portal.azure.com).
138
129
1. Click **Create a Resource** then search for **Static Web Apps** and select the matching result.
139
130
140
-
[Image of Static App]
131
+
<!--- TODO: Add screenshot for navigating to static web apps --->
141
132
142
-
1. Select a subscription from the *Subscription*dropdown list or use the default one.
143
-
1. Click the **New** link below the *Resource group*dropdown. In *New resource group name*, type**nextjsstaticsite** and click **OK**
133
+
1. Select a subscription from the *Subscription* drop-down list or use the default value.
134
+
1. Click the **New** link below the *Resource group* drop-down. In *New resource group name*, type **mystaticsite** and click **OK**
144
135
1. Provide a globally unique name for your app in the **Name** text box. Valid characters include `a-z`, `A-Z`, `0-9`, and `-`. This value is used as the URL prefix for your static app in the format of `https://<APP_NAME>.azurestaticapps.net`.
145
136
1. In the *Region* drop-down, choose a region closest to you.
146
137
1. Select **Free** from the SKU drop-down.
147
138
148
-
[Image of static app form]
139
+

149
140
150
141
### Add a GitHub repository
151
142
@@ -156,15 +147,15 @@ The new Static Web Apps account needs access to the repository with your Next.js
156
147
1. Find and select the name of the repository you created earlier.
157
148
1. Choose **master** as the branch from the *Branch* drop-down.
Azure Static Web Apps is built to automatically carry out common tasks like installing npm modules and running `npm run build` during each deployment. There are, however, a few settings like the application source folder and the build destination folder that you need to configure manually.
164
155
165
156
1. Click on the **Build** tab to configure the static output folder.
166
157
167
-
[Image highlighting the Build tab]
158
+

168
159
169
160
1. Type **out** in the *App artifact location* text box.
170
161
@@ -173,7 +164,21 @@ Azure Static Web Apps is built to automatically carry out common tasks like inst
173
164
1. Click the **Review + Create** button to verify the details are all correct.
174
165
1. Click **Create** to start the creation of the resource and also provision a GitHub Action for deployment.
175
166
1. Once the deployment is completed, click **Go to resource**
176
-
1. On the resource screen, click the *URL* link to open your deployed application.
167
+
1. On the _Overview_ window, click the *URL* link to open your deployed application.
168
+
169
+
If the website does note immediately load, then the background GitHub Actions workflow is still running. Once the workflow is complete you can then click refresh the browser to view your web app.
170
+
171
+
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. You need to bring this file down to your local repository so your git history is synchronized.
180
+
181
+
Return to the terminal and run the following command `git pull origin maser`.
177
182
178
183
## Configure dynamic routes
179
184
@@ -183,17 +188,6 @@ Navigate to the newly-deployed site and click on one of the framework or library
183
188
184
189
The reason for this error is because Next.js only generated the home page based on the application configuration.
185
190
186
-
```javascript
187
-
module.exports = {
188
-
exportTrailingSlash: true,
189
-
exportPathMap: function() {
190
-
return {
191
-
'/': { page: '/' }
192
-
};
193
-
}
194
-
};
195
-
```
196
-
197
191
## Generate static pages from dynamic routes
198
192
199
193
1. Update the _next.config.js_ file so that Next.js uses a list of all available data to generate static pages for each framework/library:
@@ -224,7 +218,7 @@ module.exports = {
224
218
> [!NOTE]
225
219
> The `exportPathMap` function is an async function, so you can make a request to an API in this function and use the returned list to generate the paths.
226
220
227
-
1. Push the new changes to your GitHub repository and wait for a few minutes while GitHub Actions builds your site again. After the build is complete, the 404 error disappears.
221
+
2. Push the new changes to your GitHub repository and wait for a few minutes while GitHub Actions builds your site again. After the build is complete, the 404 error disappears.
228
222
229
223

Copy file name to clipboardExpand all lines: articles/static-apps/deploy-nuxtjs.md
+38-34Lines changed: 38 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,18 +23,20 @@ In this tutorial, you learn to deploy a [Nuxt.js](https://nuxtjs.org) generated
23
23
24
24
You can set up a new Nuxt.js project using `create-nuxt-app`. Instead of a new project, let's clone a repository that is set up to demonstrate an edge case when you try to deploy a dynamic Nuxt.js app. The repository contains an example of a dynamic site that we want to serve as a static site.
25
25
26
-
1. Clone starter repository:
26
+
1. Create a new repository under your GitHub account from a template repository.
27
+
1. Navigate to <http://github.com/staticwebdev/nuxtjs-starter/generate>
28
+
1. Name the repository **nuxtjs-starter**
29
+
1. Next, clone the new repo to your machine. Make sure to replace <YOUR_GITHUB_ACCOUNT_NAME> with your account name.
@@ -83,53 +85,41 @@ When you build a Nuxt.js site using `npm run build`, the app is built as a tradi
83
85
84
86
## Push your static website to GitHub
85
87
86
-
Azure Static Web Apps deploys your app from a GitHub repository and keeps doing so for every pushed commit to a designated branch. Use the following command to set up a repository.
87
-
88
-
1. Initialize a git repo
88
+
Azure Static Web Apps deploys your app from a GitHub repository and keeps doing so for every pushed commit to a designated branch. Use the following commands sync your changes to GitHub.
89
89
90
+
1. Stage all changed files
90
91
```bash
91
-
# Remove existing .git
92
-
rm -rf .git
93
-
# Initialize git
94
-
git init
95
-
# Add all files
96
92
git add .
97
-
# Commit changes
98
-
git commit -m "initial commit"
99
93
```
100
-
101
-
1. Create a blank GitHub repo (don't create a README) from [https://github.com/new](https://github.com/new) and name it whatever you like for example, **nuxtjs-static-website**.
102
-
103
-
1. Add the GitHub repo as a remote to your local repo.
The following steps show how to deploy the app you just pushed to GitHub to Azure Static Web Apps. Once in Azure you can deploy the application to a production environment.
107
+
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.
118
108
119
109
### Create Azure App Service Static App
120
110
121
111
1. Navigate to the [Azure Portal](https://portal.azure.com).
122
112
1. Click **Create a Resource** then search for **Static Web Apps** and select the matching result.
123
113
124
-
[Image of Static App]
114
+
<!--- TODO: Add screenshot for navigating to static web apps --->
125
115
126
-
1. Select a subscription from the *Subscription*dropdown list or use the default one.
127
-
1. Click the **New** link below the *Resource group*dropdown. In *New resource group name*, type**nuxtjsstaticsite** and click **OK**
116
+
1. Select a subscription from the *Subscription* drop-down list or use the default value.
117
+
1. Click the **New** link below the *Resource group* drop-down. In *New resource group name*, type **mystaticsite** and click **OK**
128
118
1. Provide a globally unique name for your app in the **Name** text box. Valid characters include `a-z`, `A-Z`, `0-9`, and `-`. This value is used as the URL prefix for your static app in the format of `https://<APP_NAME>.azurestaticapps.net`.
129
119
1. In the *Region* drop-down, choose a region closest to you.
130
120
1. Select **Free** from the SKU drop-down.
131
121
132
-
[Image of static app form]
122
+

133
123
134
124
### Add a GitHub repository
135
125
@@ -140,15 +130,15 @@ The new Static Web Apps account needs access to the repository with your Nuxt.js
140
130
1. Find and select the name of the repository you created earlier.
141
131
1. Choose **master** as the branch from the *Branch* drop-down.
Azure Static Web Apps is built to automatically carry out common tasks like installing npm modules and running `npm run build` during each deployment. There are, however, a few settings like the application source folder and the build destination folder that you need to configure manually.
148
138
149
139
1. Click on the **Build** tab to configure the static output folder.
150
140
151
-
[Image highlighting the Build tab]
141
+

152
142
153
143
1. Type **dist** in the *App artifact location* text box.
154
144
@@ -157,7 +147,21 @@ Azure Static Web Apps is built to automatically carry out common tasks like inst
157
147
1. Click the **Review + Create** button to verify the details are all correct.
158
148
1. Click **Create** to start the creation of the resource and also provision a GitHub Action for deployment.
159
149
1. Once the deployment is completed, click **Go to resource**
160
-
1. On the resource screen, click the *URL* link to open your deployed application.
150
+
1. On the _Overview_ window, click the *URL* link to open your deployed application.
151
+
152
+
If the website does note immediately load, then the background GitHub Actions workflow is still running. Once the workflow is complete you can then click refresh the browser to view your web app.
153
+
154
+
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. You need to bring this file down to your local repository so your git history is synchronized.
163
+
164
+
Return to the terminal and run the following command `git pull origin maser`.
161
165
162
166
## Configure dynamic routes
163
167
@@ -198,7 +202,7 @@ If the page is a dynamic page, for example `_id.vue`, it won't have enough infor
198
202
> [!NOTE]
199
203
>`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.
200
204
201
-
1. Push the new changes to your GitHub repository and wait for a few minutes while GitHub Actions builds your site again. After the build is complete, the 404 error disappears.
205
+
2. Push the new changes to your GitHub repository and waitfor a few minutes while GitHub Actions builds your site again. After the build is complete, the 404 error disappears.
202
206
203
207

0 commit comments