cf部署支持

This commit is contained in:
mtvpls
2026-01-23 17:26:20 +08:00
parent 6eaed34b14
commit 8d971650c5
7 changed files with 5358 additions and 19 deletions

5
.gitignore vendored
View File

@@ -33,6 +33,11 @@ yarn-error.log*
# vercel
.vercel
# cloudflare
.open-next/
.wrangler/
wrangler.toml.bak
# typescript
*.tsbuildinfo
next-env.d.ts

1
.node-version Normal file
View File

@@ -0,0 +1 @@
24

View File

@@ -1,8 +1,12 @@
/** @type {import('next').NextConfig} */
/* eslint-disable @typescript-eslint/no-var-requires */
// 检测是否为 Cloudflare Pages 构建
const isCloudflare = process.env.CF_PAGES === '1' || process.env.BUILD_TARGET === 'cloudflare';
const nextConfig = {
output: 'standalone',
// Cloudflare Pages 不支持 standalone,使用默认输出
output: isCloudflare ? undefined : 'standalone',
eslint: {
dirs: ['src'],
// 在生产构建时忽略 ESLint 错误
@@ -13,7 +17,7 @@ const nextConfig = {
swcMinify: true,
experimental: {
instrumentationHook: process.env.NODE_ENV === 'production',
instrumentationHook: process.env.NODE_ENV === 'production' && !isCloudflare,
},
// Uncoment to add domain whitelist

28
open-next.config.ts Normal file
View File

@@ -0,0 +1,28 @@
import type { OpenNextConfig } from '@opennextjs/cloudflare';
const config: OpenNextConfig = {
default: {
override: {
wrapper: 'cloudflare-node',
converter: 'edge',
proxyExternalRequest: 'fetch',
incrementalCache: 'dummy',
tagCache: 'dummy',
queue: 'dummy',
},
},
edgeExternals: ['node:crypto'],
middleware: {
external: true,
override: {
wrapper: 'cloudflare-edge',
converter: 'edge',
proxyExternalRequest: 'fetch',
incrementalCache: 'dummy',
tagCache: 'dummy',
queue: 'dummy',
},
},
};
export default config;

View File

@@ -5,7 +5,10 @@
"scripts": {
"dev": "pnpm gen:manifest && node server.js",
"build": "pnpm gen:manifest && next build",
"build:cloudflare": "BUILD_TARGET=cloudflare pnpm gen:manifest && npx @opennextjs/cloudflare build",
"start": "NODE_ENV=production node server.js",
"preview:cloudflare": "wrangler dev",
"deploy:cloudflare": "wrangler deploy",
"lint": "next lint",
"lint:fix": "eslint src --fix && pnpm format",
"lint:strict": "eslint --max-warnings=0 src",
@@ -72,6 +75,7 @@
"devDependencies": {
"@commitlint/cli": "^16.3.0",
"@commitlint/config-conventional": "^16.2.4",
"@opennextjs/cloudflare": "^1.15.1",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/forms": "^0.5.10",
"@tailwindcss/typography": "^0.5.19",
@@ -104,6 +108,7 @@
"prettier-plugin-tailwindcss": "^0.5.0",
"tailwindcss": "^3.4.17",
"typescript": "^4.9.5",
"vercel": "^50.4.10",
"webpack-obfuscator": "^3.5.1"
},
"lint-staged": {

5316
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

14
wrangler.toml Normal file
View File

@@ -0,0 +1,14 @@
name = "moontv-plus"
compatibility_date = "2024-01-01"
main = ".open-next/worker.js"
# Cloudflare Pages 配置
# 构建命令: pnpm build:cloudflare
# 主文件: .open-next/worker.js
# 静态资源
[site]
bucket = ".open-next/assets"
[env.production]
# 生产环境变量可以在 Cloudflare Pages 控制台配置