lobe-chat

Форк
0
/
next.config.mjs 
251 строка · 6.5 Кб
1
import analyzer from '@next/bundle-analyzer';
2
import { withSentryConfig } from '@sentry/nextjs';
3
import withSerwistInit from '@serwist/next';
4

5
const isProd = process.env.NODE_ENV === 'production';
6
const buildWithDocker = process.env.DOCKER === 'true';
7

8
// if you need to proxy the api endpoint to remote server
9
const API_PROXY_ENDPOINT = process.env.API_PROXY_ENDPOINT || '';
10

11
const basePath = process.env.NEXT_PUBLIC_BASE_PATH;
12

13
/** @type {import('next').NextConfig} */
14
const nextConfig = {
15
  basePath,
16
  compress: isProd,
17
  experimental: {
18
    optimizePackageImports: [
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
    ],
27
    webVitalsAttribution: ['CLS', 'LCP'],
28
  },
29

30
  async headers() {
31
    return [
32
      {
33
        headers: [
34
          {
35
            key: 'Cache-Control',
36
            value: 'public, max-age=31536000, immutable',
37
          },
38
        ],
39
        source: '/icons/(.*).(png|jpe?g|gif|svg|ico|webp)',
40
      },
41
      {
42
        headers: [
43
          {
44
            key: 'Cache-Control',
45
            value: 'public, max-age=31536000, immutable',
46
          },
47
        ],
48
        source: '/images/(.*).(png|jpe?g|gif|svg|ico|webp)',
49
      },
50
      {
51
        headers: [
52
          {
53
            key: 'Cache-Control',
54
            value: 'public, max-age=31536000, immutable',
55
          },
56
        ],
57
        source: '/videos/(.*).(mp4|webm|ogg|avi|mov|wmv|flv|mkv)',
58
      },
59
      {
60
        headers: [
61
          {
62
            key: 'Cache-Control',
63
            value: 'public, max-age=31536000, immutable',
64
          },
65
        ],
66
        source: '/screenshots/(.*).(png|jpe?g|gif|svg|ico|webp)',
67
      },
68
      {
69
        headers: [
70
          {
71
            key: 'Cache-Control',
72
            value: 'public, max-age=31536000, immutable',
73
          },
74
        ],
75
        source: '/og/(.*).(png|jpe?g|gif|svg|ico|webp)',
76
      },
77
      {
78
        headers: [
79
          {
80
            key: 'Cache-Control',
81
            value: 'public, max-age=31536000, immutable',
82
          },
83
        ],
84
        source: '/favicon.ico',
85
      },
86
      {
87
        headers: [
88
          {
89
            key: 'Cache-Control',
90
            value: 'public, max-age=31536000, immutable',
91
          },
92
        ],
93
        source: '/favicon-32x32.ico',
94
      },
95
      {
96
        headers: [
97
          {
98
            key: 'Cache-Control',
99
            value: 'public, max-age=31536000, immutable',
100
          },
101
        ],
102
        source: '/apple-touch-icon.png',
103
      },
104
    ];
105
  },
106

107
  output: buildWithDocker ? 'standalone' : undefined,
108
  reactStrictMode: true,
109
  redirects: async () => [
110
    {
111
      destination: '/sitemap-index.xml',
112
      permanent: true,
113
      source: '/sitemap.xml',
114
    },
115
    {
116
      destination: '/sitemap-index.xml',
117
      permanent: true,
118
      source: '/sitemap-0.xml',
119
    },
120
    {
121
      destination: '/manifest.webmanifest',
122
      permanent: true,
123
      source: '/manifest.json',
124
    },
125
    {
126
      destination: '/discover/assistant/:slug',
127
      has: [
128
        {
129
          key: 'agent',
130
          type: 'query',
131
          value: '(?<slug>.*)',
132
        },
133
      ],
134
      permanent: true,
135
      source: '/market',
136
    },
137
    {
138
      destination: '/discover/assistants',
139
      permanent: true,
140
      source: '/discover/assistant',
141
    },
142
    {
143
      destination: '/discover/models',
144
      permanent: true,
145
      source: '/discover/model',
146
    },
147
    {
148
      destination: '/discover/plugins',
149
      permanent: true,
150
      source: '/discover/plugin',
151
    },
152
    {
153
      destination: '/discover/providers',
154
      permanent: true,
155
      source: '/discover/provider',
156
    },
157
    {
158
      destination: '/settings/common',
159
      permanent: true,
160
      source: '/settings',
161
    },
162
  ],
163

164
  rewrites: async () => [
165
    // due to google api not work correct in some countries
166
    // we need a proxy to bypass the restriction
167
    { destination: `${API_PROXY_ENDPOINT}/api/chat/google`, source: '/api/chat/google' },
168
  ],
169

170
  webpack(config) {
171
    config.experiments = {
172
      asyncWebAssembly: true,
173
      layers: true,
174
    };
175

176
    // to fix shikiji compile error
177
    // refs: https://github.com/antfu/shikiji/issues/23
178
    config.module.rules.push({
179
      resolve: {
180
        fullySpecified: false,
181
      },
182
      test: /\.m?js$/,
183
      type: 'javascript/auto',
184
    });
185

186
    // https://github.com/pinojs/pino/issues/688#issuecomment-637763276
187
    config.externals.push('pino-pretty');
188

189
    config.resolve.alias.canvas = false;
190

191
    return config;
192
  },
193
};
194

195
const noWrapper = (config) => config;
196

197
const withBundleAnalyzer = process.env.ANALYZE === 'true' ? analyzer() : noWrapper;
198

199
const withPWA = isProd
200
  ? withSerwistInit({
201
      register: false,
202
      swDest: 'public/sw.js',
203
      swSrc: 'src/app/sw.ts',
204
    })
205
  : noWrapper;
206

207
const hasSentry = !!process.env.NEXT_PUBLIC_SENTRY_DSN;
208
const withSentry =
209
  isProd && hasSentry
210
    ? (c) =>
211
        withSentryConfig(
212
          c,
213
          {
214
            org: process.env.SENTRY_ORG,
215

216
            project: process.env.SENTRY_PROJECT,
217
            // For all available options, see:
218
            // https://github.com/getsentry/sentry-webpack-plugin#options
219
            // Suppresses source map uploading logs during build
220
            silent: 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-jobs
227
            automaticVercelMonitors: true,
228

229
            // Automatically tree-shake Sentry logger statements to reduce bundle size
230
            disableLogger: true,
231

232
            // Hides source maps from generated client bundles
233
            hideSourceMaps: true,
234

235
            // Transpiles SDK to be compatible with IE11 (increases bundle size)
236
            transpileClientSDK: 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.
241
            tunnelRoute: '/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)
246
            widenClientFileUpload: true,
247
          },
248
        )
249
    : noWrapper;
250

251
export default withBundleAnalyzer(withPWA(withSentry(nextConfig)));
252

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.