Skip to content

Commit e9fe74f

Browse files
committed
Remove cp from nextjs.yml and put it in next.config.mjs, together with 'start' command update
1 parent 336ec6e commit e9fe74f

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

.github/workflows/nextjs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: Install dependencies
7676
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
7777
- name: Build with Next.js
78-
run: ${{ steps.detect-package-manager.outputs.runner }} next build && cp -r ./public ./.next/standalone/ && cp -r ./.next/static ./.next/standalone/.next/
78+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
7979
env:
8080
REACT_APP_ALCHEMY_API_KEY: ${{ secrets.REACT_APP_ALCHEMY_API_KEY }}
8181
REACT_APP_ETHERSCAN_API_KEY: ${{ secrets.REACT_APP_ETHERSCAN_API_KEY }}

LEARNING.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,45 @@ const nextConfig = {
2525

2626
export default nextConfig;
2727
```
28-
2928
> [!NOTE]
3029
> When using `output: 'export'` instead of `output: 'standalone'`, Nextjs will throw the runtime Error `Page "/[network]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.` because of the use of the dynamic route `[network]`.
3130
32-
### 2. Add the environment variables to Github
31+
### 2. Update `package.json` for `output: 'standalone'`
32+
In `package.json`, update the `"build"` and `"start"` commands of the `"scripts"` field:
33+
```json
34+
"scripts": {
35+
"dev": "next dev -p 3005",
36+
"build": "next build && cp -r ./public ./.next/standalone/ && cp -r ./.next/static ./.next/standalone/.next/",
37+
"start": "node .next/standalone/server.js",
38+
"lint": "next lint"
39+
},
40+
```
41+
**Without this `start` command the page will 404!**
42+
Without the `cp` command, the Github Pages URL will not find any CSS files. But note that `cp` will not run on Windows, so if you use Windows you should still manually copy these 2 folders after running `npm run build`. This is not a problem for Github Pages though, since it deploys to Linux.
43+
44+
### 3. Add the environment variables to Github
3345
- On Github, navigate to the `Settings` tab of your project, and select `Environments` from the menu on the left-hand side.
3446
- Select the`github-pages` environment, and under `Environment secrets`, click `Add environment secret` and add `REACT_APP_ALCHEMY_API_KEY` and its value.
3547
- Click `Add environment secret` again and add `REACT_APP_ETHERSCAN_API_KEY` and its value.
3648

37-
### 3. Activate GitHub Pages for Repository
49+
### 4. Activate GitHub Pages for Repository
3850
- Now, still under the `Settings` tab of your project, select `Pages` from the menu on the left-hand side.
3951
- Locate the `Source` dropdown, which is likely set to `Deploy from a branch`.
4052
- Click `Deploy from a branch` and switch it to `Github Actions`.
4153
- Click `Configure` in the Github Actions field, which will take you to a `/.github/workflows/nextjs.yml` action configuration file.
42-
- In this file, we need to add the API keys to the build step, as well as copy some extra folders to the build output because of the `output: 'standalone'`. Find the following text:
54+
- In this file, we need to add the API keys to the build step. Find the following text:
4355
```yml
4456
- name: Build with Next.js
4557
run: ${{ steps.detect-package-manager.outputs.runner }} next build
4658
```
47-
Now, add ` && cp -r ./public ./.next/standalone/ && cp -r ./.next/static ./.next/standalone/.next/` to the build command, and add the following `env` section:
59+
And add the following `env` section:
4860
```yml
4961
- name: Build with Next.js
50-
run: ${{ steps.detect-package-manager.outputs.runner }} next build && cp -r ./public ./.next/standalone/ && cp -r ./.next/static ./.next/standalone/.next/
62+
run: ${{ steps.detect-package-manager.outputs.runner }} next build
5163
env:
5264
REACT_APP_ALCHEMY_API_KEY: ${{ secrets.REACT_APP_ALCHEMY_API_KEY }}
5365
REACT_APP_ETHERSCAN_API_KEY: ${{ secrets.REACT_APP_ETHERSCAN_API_KEY }}
5466
```
55-
**Without the `cp` command**, the Github Pages URL will not find the requested files, and **your page will 404!**
5667
- In the next section of that same file, update the `path` where the binaries are located; change `path: ./out` to `path: ./.next/standalone`:
5768
```yml
5869
- name: Upload artifact

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"scripts": {
2222
"dev": "next dev -p 3005",
23-
"build": "next build",
24-
"start": "next start",
23+
"build": "next build && cp -r ./public ./.next/standalone/ && cp -r ./.next/static ./.next/standalone/.next/",
24+
"start": "node .next/standalone/server.js",
2525
"lint": "next lint"
2626
},
2727
"dependencies": {

0 commit comments

Comments
 (0)