Skip to content

Commit 4711022

Browse files
Merge pull request #242582 from thomasgauvin/patch-10
Fix NuxtJS doc (based on a previous commit)
2 parents 4f03579 + 356f1ee commit 4711022

File tree

1 file changed

+15
-81
lines changed

1 file changed

+15
-81
lines changed

articles/static-web-apps/deploy-nuxtjs.md

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ In this tutorial, you learn to deploy a [Nuxt 3](https://v3.nuxtjs.org/) applica
2424

2525
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.
2626

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).
2928
1. Name the repository **nuxt-3-starter**.
3029
1. Next, clone the new repo to your machine. Make sure to replace <YOUR_GITHUB_ACCOUNT_NAME> with your account name.
3130

3231
```bash
3332
git clone http://github.com/<YOUR_GITHUB_ACCOUNT_NAME>/nuxt-3-starter
3433
```
3534

36-
1. Go to the newly cloned Nuxt.js app:
35+
1. Navigate to the newly cloned Nuxt.js app:
3736

3837
```bash
3938
cd nuxt-3-starter
@@ -51,47 +50,17 @@ You can set up a new Nuxt project using `npx nuxi init nuxt-app`. Instead of usi
5150
npm run dev -- -o
5251
```
5352

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.
5554

5655
:::image type="content" source="media/deploy-nuxtjs/nuxt-3-app.png" alt-text="Start Nuxt.js app":::
5756

58-
When you select a framework/library, you should see a details page about the selected item:
57+
## Deploy your Nuxt 3 site
5958

60-
:::image type="content" source="media/deploy-nuxtjs/start-nuxtjs-details.png" alt-text="Details page":::
61-
62-
## Generate a static website from Nuxt.js build
63-
64-
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.
9160

9261
### Create an Azure Static Web Apps resource
9362

94-
1. Go to the [Azure portal](https://portal.azure.com).
63+
1. Navigate to the [Azure portal](https://portal.azure.com).
9564
1. Select **Create a Resource**.
9665
1. Search for **Static Web Apps**.
9766
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
12796

12897
1. Select **Review + Create** to verify the details are all correct.
12998

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.
131100

132-
3. Once the deployment completes, select **Go to resource**.
101+
1. Once the deployment completes, select **Go to resource**.
133102

134-
4. On the _Overview_ window, select the *URL* link to open your deployed application.
103+
1. On the _Overview_ window, select the *URL* link to open your deployed application.
135104

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.
137106

138107
You can check the status of the Actions workflows by navigating to the Actions for your repository:
139108

@@ -143,50 +112,15 @@ https://github.com/<YOUR_GITHUB_USERNAME>/nuxt-3-starter/actions
143112

144113
### Synchronize changes
145114

146-
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.
149116

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 function and use the returned list to generate the paths.
117+
```bash
118+
git pull
119+
```
186120

187121
Make changes to the app by updating the code and pushing it to GitHub. GitHub Actions automatically builds and deploys the app.
188122

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).
190124

191125
> [!div class="nextstepaction"]
192126
> [Set up a custom domain](custom-domain.md)

0 commit comments

Comments
 (0)