优化开发编译速度

This commit is contained in:
mtvpls
2026-05-29 22:54:11 +08:00
parent b121b328c3
commit e74c7b15e0
2 changed files with 24 additions and 9 deletions
+22 -8
View File
@@ -1,6 +1,8 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
// 检测是否为 Cloudflare Pages 构建 // 检测是否为 Cloudflare Pages 构建
const isCloudflare = process.env.CF_PAGES === '1' || process.env.BUILD_TARGET === 'cloudflare'; const isCloudflare = process.env.CF_PAGES === '1' || process.env.BUILD_TARGET === 'cloudflare';
@@ -9,6 +11,9 @@ const optimizedPackageImports = [
'@dnd-kit/modifiers', '@dnd-kit/modifiers',
'@dnd-kit/sortable', '@dnd-kit/sortable',
'@dnd-kit/utilities', '@dnd-kit/utilities',
'@heroicons/react',
'lucide-react',
'react-icons',
]; ];
const serverExternalPackages = [ const serverExternalPackages = [
@@ -24,7 +29,10 @@ const serverExternalPackages = [
'xpath', 'xpath',
]; ];
const nextConfig = { const createNextConfig = (phase) => {
const isDevelopment = phase === PHASE_DEVELOPMENT_SERVER || process.env.NODE_ENV === 'development';
const nextConfig = {
// Cloudflare Pages 不支持 standalone,使用默认输出 // Cloudflare Pages 不支持 standalone,使用默认输出
output: isCloudflare ? undefined : 'standalone', output: isCloudflare ? undefined : 'standalone',
eslint: { eslint: {
@@ -117,11 +125,17 @@ const nextConfig = {
}, },
}; };
const withPWA = require('next-pwa')({ if (isDevelopment) {
dest: 'public', return nextConfig;
disable: process.env.NODE_ENV === 'development', }
register: true,
skipWaiting: true,
});
module.exports = withPWA(nextConfig); const withPWA = require('next-pwa')({
dest: 'public',
register: true,
skipWaiting: true,
});
return withPWA(nextConfig);
};
module.exports = createNextConfig;
+2 -1
View File
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any,no-console */ /* eslint-disable @typescript-eslint/no-explicit-any,no-console */
import bs58 from 'bs58'; import bs58 from 'bs58';
import he from 'he'; import he from 'he';
import Hls from 'hls.js';
export type DoubanImageProxyType = export type DoubanImageProxyType =
| 'direct' | 'direct'
@@ -509,6 +508,8 @@ export async function getVideoResolutionFromM3u8(
bitrate: string; // 视频码率(如 "2.5 Mbps" bitrate: string; // 视频码率(如 "2.5 Mbps"
}> { }> {
try { try {
const { default: Hls } = await import('hls.js');
// 直接使用m3u8 URL作为视频源,避免CORS问题 // 直接使用m3u8 URL作为视频源,避免CORS问题
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const video = document.createElement('video'); const video = document.createElement('video');