Skip to content

Commit 5766a69

Browse files
committed
init
1 parent 4e2e25a commit 5766a69

File tree

7 files changed

+147
-11
lines changed

7 files changed

+147
-11
lines changed

.github/workflows/nextjs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ jobs:
7575
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
7676
- name: Build with Next.js
7777
run: ${{ steps.detect-package-manager.outputs.runner }} next build
78-
- name: Static HTML export with Next.js
79-
run: ${{ steps.detect-package-manager.outputs.runner }} next export || echo "next export is not needed with Next.js 13.3+"
78+
# 移除这一步骤,因为 Next.js 15.x 不需要单独的 export 命令
79+
# - name: Static HTML export with Next.js
80+
# run: ${{ steps.detect-package-manager.outputs.runner }} next export || echo "next export is not needed with Next.js 13.3+"
8081
- name: Upload artifact
8182
uses: actions/upload-pages-artifact@v3
8283
with:

2024-07-13-11-45-30.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Next.js GitHub Pages部署修复记录
2+
3+
## 问题
4+
GitHub Pages部署失败,显示 "Deploy Next.js site to Pages / build (push) Failing after 21s"。
5+
6+
## 原因分析
7+
1. Next.js 15.x版本需要特定的静态导出配置
8+
2. Tailwind CSS配置不完整或不兼容
9+
3. GitHub Actions工作流配置不适合新版Next.js
10+
11+
## 解决方案
12+
13+
### 1. 修改 next.config.ts
14+
- 添加 `output: 'export'` 配置以支持静态导出
15+
- 添加 `trailingSlash: true` 以兼容GitHub Pages的URL结构
16+
- 设置 `unoptimized: true` 以禁用服务器端图像优化
17+
18+
```typescript
19+
/** @type {import('next').NextConfig} */
20+
21+
const nextConfig = {
22+
output: 'export',
23+
trailingSlash: true,
24+
images: {
25+
remotePatterns: [
26+
// ...配置保持不变
27+
],
28+
dangerouslyAllowSVG: true,
29+
unoptimized: true,
30+
},
31+
};
32+
33+
export default nextConfig;
34+
```
35+
36+
### 2. 更新GitHub Actions工作流配置
37+
- 删除不必要的 `next export` 命令,因为新版Next.js的`build`命令已经包含导出功能
38+
39+
### 3. 修复Tailwind CSS配置
40+
- 更新 postcss.config.mjs 以正确配置Tailwind CSS和autoprefixer
41+
- 创建正确的tailwind.config.js文件在根目录
42+
- 在components.json中指向正确的Tailwind配置文件
43+
44+
### 4. 修复包依赖
45+
- 添加autoprefixer和postcss依赖
46+
- 确保依赖版本兼容
47+
48+
## 测试
49+
推送更改到GitHub仓库后,GitHub Actions应该能够成功构建并部署站点到GitHub Pages。

components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"rsc": true,
55
"tsx": true,
66
"tailwind": {
7-
"config": "",
7+
"config": "tailwind.config.js",
88
"css": "app/globals.css",
99
"baseColor": "neutral",
1010
"cssVariables": true,

next.config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { NextConfig } from "next";
1+
/** @type {import('next').NextConfig} */
22

3-
const nextConfig: NextConfig = {
4-
/* config options here */
5-
output: 'export', // 添加静态输出配置,生成静态HTML文件
6-
basePath: '', // 如果项目不在子目录下可以保持为空
3+
const nextConfig = {
4+
output: 'export',
5+
// 为了兼容 GitHub Pages,设置 trailingSlash 为 true
6+
trailingSlash: true,
7+
// 删除 basePath 配置,让它使用默认值
78
images: {
89
remotePatterns: [
910
{

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
"vaul": "^1.1.2"
4141
},
4242
"devDependencies": {
43-
"@tailwindcss/postcss": "^4",
4443
"@types/node": "^20",
45-
"@types/react": "^init",
44+
"@types/react": "^19",
4645
"@types/react-dom": "^19",
46+
"autoprefixer": "^10.0.1",
47+
"postcss": "^8",
4748
"prettier": "^3.5.3",
4849
"tailwindcss": "^4",
4950
"typescript": "^5"

postcss.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const config = {
2-
plugins: ["@tailwindcss/postcss"],
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
36
};
47

58
export default config;

tailwind.config.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
darkMode: ["class"],
4+
content: [
5+
"./pages/**/*.{ts,tsx}",
6+
"./components/**/*.{ts,tsx}",
7+
"./app/**/*.{ts,tsx}",
8+
"./src/**/*.{ts,tsx}",
9+
"./data/**/*.{ts,tsx}",
10+
],
11+
prefix: "",
12+
theme: {
13+
screens: {
14+
'tablet': '1280px',
15+
'laptop': '1280px',
16+
},
17+
extend: {
18+
spacing: {
19+
"128": "32rem",
20+
"high": "50rem",
21+
"widequater": "14rem",
22+
"wide": "60rem",
23+
"wider": "73rem",
24+
"landing": "88rem",
25+
},
26+
colors: {
27+
"o-blue": "#00a0e8",
28+
"o-light-blue": "#53c2f0",
29+
"o-dark-blue": "#0c318f",
30+
"o-white": "#e9e9e9",
31+
"o-black": "#212121",
32+
"o-gray": '#9ca3af',
33+
"o-hover": '#f9fafb',
34+
"demo-c1": '#00a0e8',
35+
"demo-c2": '#d847f0',
36+
"drama-white": "#ffffff",
37+
"drama-black": "#0d0d0d",
38+
border: "var(--color-border)",
39+
input: "var(--color-input)",
40+
ring: "var(--color-ring)",
41+
background: "var(--color-background)",
42+
foreground: "var(--color-foreground)",
43+
primary: {
44+
DEFAULT: "var(--color-primary)",
45+
foreground: "var(--color-primary-foreground)",
46+
},
47+
secondary: {
48+
DEFAULT: "var(--color-secondary)",
49+
foreground: "var(--color-secondary-foreground)",
50+
},
51+
destructive: {
52+
DEFAULT: "var(--color-destructive)",
53+
foreground: "var(--color-destructive-foreground)",
54+
},
55+
muted: {
56+
DEFAULT: "var(--color-muted)",
57+
foreground: "var(--color-muted-foreground)",
58+
},
59+
accent: {
60+
DEFAULT: "var(--color-accent)",
61+
foreground: "var(--color-accent-foreground)",
62+
},
63+
popover: {
64+
DEFAULT: "var(--color-popover)",
65+
foreground: "var(--color-popover-foreground)",
66+
},
67+
card: {
68+
DEFAULT: "var(--color-card)",
69+
foreground: "var(--color-card-foreground)",
70+
},
71+
},
72+
borderRadius: {
73+
lg: "var(--radius-lg)",
74+
md: "var(--radius-md)",
75+
sm: "var(--radius-sm)",
76+
xl: "var(--radius-xl)",
77+
},
78+
},
79+
},
80+
plugins: [],
81+
}

0 commit comments

Comments
 (0)