lobe-chat
/
next.config.mjs
251 строка · 6.5 Кб
1import analyzer from '@next/bundle-analyzer';2import { withSentryConfig } from '@sentry/nextjs';3import withSerwistInit from '@serwist/next';4
5const isProd = process.env.NODE_ENV === 'production';6const buildWithDocker = process.env.DOCKER === 'true';7
8// if you need to proxy the api endpoint to remote server
9const API_PROXY_ENDPOINT = process.env.API_PROXY_ENDPOINT || '';10
11const basePath = process.env.NEXT_PUBLIC_BASE_PATH;12
13/** @type {import('next').NextConfig} */
14const nextConfig = {15basePath,16compress: isProd,17experimental: {18optimizePackageImports: [19'emoji-mart',20'@emoji-mart/react',21'@emoji-mart/data',22'@icons-pack/react-simple-icons',23'@lobehub/ui',24'gpt-tokenizer',25'chroma-js',26],27webVitalsAttribution: ['CLS', 'LCP'],28},29
30async headers() {31return [32{33headers: [34{35key: 'Cache-Control',36value: 'public, max-age=31536000, immutable',37},38],39source: '/icons/(.*).(png|jpe?g|gif|svg|ico|webp)',40},41{42headers: [43{44key: 'Cache-Control',45value: 'public, max-age=31536000, immutable',46},47],48source: '/images/(.*).(png|jpe?g|gif|svg|ico|webp)',49},50{51headers: [52{53key: 'Cache-Control',54value: 'public, max-age=31536000, immutable',55},56],57source: '/videos/(.*).(mp4|webm|ogg|avi|mov|wmv|flv|mkv)',58},59{60headers: [61{62key: 'Cache-Control',63value: 'public, max-age=31536000, immutable',64},65],66source: '/screenshots/(.*).(png|jpe?g|gif|svg|ico|webp)',67},68{69headers: [70{71key: 'Cache-Control',72value: 'public, max-age=31536000, immutable',73},74],75source: '/og/(.*).(png|jpe?g|gif|svg|ico|webp)',76},77{78headers: [79{80key: 'Cache-Control',81value: 'public, max-age=31536000, immutable',82},83],84source: '/favicon.ico',85},86{87headers: [88{89key: 'Cache-Control',90value: 'public, max-age=31536000, immutable',91},92],93source: '/favicon-32x32.ico',94},95{96headers: [97{98key: 'Cache-Control',99value: 'public, max-age=31536000, immutable',100},101],102source: '/apple-touch-icon.png',103},104];105},106
107output: buildWithDocker ? 'standalone' : undefined,108reactStrictMode: true,109redirects: async () => [110{111destination: '/sitemap-index.xml',112permanent: true,113source: '/sitemap.xml',114},115{116destination: '/sitemap-index.xml',117permanent: true,118source: '/sitemap-0.xml',119},120{121destination: '/manifest.webmanifest',122permanent: true,123source: '/manifest.json',124},125{126destination: '/discover/assistant/:slug',127has: [128{129key: 'agent',130type: 'query',131value: '(?<slug>.*)',132},133],134permanent: true,135source: '/market',136},137{138destination: '/discover/assistants',139permanent: true,140source: '/discover/assistant',141},142{143destination: '/discover/models',144permanent: true,145source: '/discover/model',146},147{148destination: '/discover/plugins',149permanent: true,150source: '/discover/plugin',151},152{153destination: '/discover/providers',154permanent: true,155source: '/discover/provider',156},157{158destination: '/settings/common',159permanent: true,160source: '/settings',161},162],163
164rewrites: async () => [165// due to google api not work correct in some countries166// we need a proxy to bypass the restriction167{ destination: `${API_PROXY_ENDPOINT}/api/chat/google`, source: '/api/chat/google' },168],169
170webpack(config) {171config.experiments = {172asyncWebAssembly: true,173layers: true,174};175
176// to fix shikiji compile error177// refs: https://github.com/antfu/shikiji/issues/23178config.module.rules.push({179resolve: {180fullySpecified: false,181},182test: /\.m?js$/,183type: 'javascript/auto',184});185
186// https://github.com/pinojs/pino/issues/688#issuecomment-637763276187config.externals.push('pino-pretty');188
189config.resolve.alias.canvas = false;190
191return config;192},193};194
195const noWrapper = (config) => config;196
197const withBundleAnalyzer = process.env.ANALYZE === 'true' ? analyzer() : noWrapper;198
199const withPWA = isProd200? withSerwistInit({201register: false,202swDest: 'public/sw.js',203swSrc: 'src/app/sw.ts',204})205: noWrapper;206
207const hasSentry = !!process.env.NEXT_PUBLIC_SENTRY_DSN;208const withSentry =209isProd && hasSentry210? (c) =>211withSentryConfig(212c,213{214org: process.env.SENTRY_ORG,215
216project: process.env.SENTRY_PROJECT,217// For all available options, see:218// https://github.com/getsentry/sentry-webpack-plugin#options219// Suppresses source map uploading logs during build220silent: true,221},222{223// Enables automatic instrumentation of Vercel Cron Monitors.224// See the following for more information:225// https://docs.sentry.io/product/crons/226// https://vercel.com/docs/cron-jobs227automaticVercelMonitors: true,228
229// Automatically tree-shake Sentry logger statements to reduce bundle size230disableLogger: true,231
232// Hides source maps from generated client bundles233hideSourceMaps: true,234
235// Transpiles SDK to be compatible with IE11 (increases bundle size)236transpileClientSDK: true,237
238// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. (increases server load)239// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-240// side errors will fail.241tunnelRoute: '/monitoring',242
243// For all available options, see:244// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/245// Upload a larger set of source maps for prettier stack traces (increases build time)246widenClientFileUpload: true,247},248)249: noWrapper;250
251export default withBundleAnalyzer(withPWA(withSentry(nextConfig)));252