generated from Amery2010/nextjs-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 236
/
next.config.js
71 lines (66 loc) · 2.32 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/** @type {import('next').NextConfig} */
const { PHASE_PRODUCTION_BUILD, PHASE_EXPORT } = require('next/constants')
const mode = process.env.NEXT_PUBLIC_BUILD_MODE
const basePath = process.env.EXPORT_BASE_PATH || ''
const apiKey = process.env.GEMINI_API_KEY || ''
const uploadProxyUrl = process.env.GEMINI_UPLOAD_BASE_URL || 'https://generativelanguage.googleapis.com'
/** @type {(phase: string, defaultConfig: import("next").NextConfig) => Promise<import("next").NextConfig>} */
module.exports = async (phase) => {
const nextConfig = {
transpilePackages: ['crypto-js', 'lodash-es'],
images: {
unoptimized: mode === 'export',
},
}
if (mode === 'export') {
nextConfig.output = 'export'
// Only used for static deployment, the default deployment directory is the root directory
nextConfig.basePath = basePath
} else if (mode === 'standalone') {
nextConfig.output = 'standalone'
}
if (mode !== 'export') {
nextConfig.rewrites = async () => {
return {
beforeFiles: apiKey
? [
{
source: '/api/google/upload/v1beta/files',
has: [
{
type: 'query',
key: 'uploadType',
value: '(?<uploadType>.*)',
},
],
destination: `${uploadProxyUrl}/upload/v1beta/files?key=${apiKey}&uploadType=:uploadType`,
},
{
source: '/api/google/v1beta/files/:id',
destination: `${uploadProxyUrl}/v1beta/files/:id?key=${apiKey}`,
},
]
: [
{
source: '/api/google/upload/v1beta/files',
destination: '/api/upload/files',
},
{
source: '/api/google/v1beta/files/:path',
destination: '/api/upload/files?id=:path',
},
],
}
}
}
if (phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT) {
const withSerwist = (await import('@serwist/next')).default({
// Note: This is only an example. If you use Pages Router,
// use something else that works, such as "service-worker/index.ts".
swSrc: 'app/sw.ts',
swDest: 'public/sw.js',
})
return withSerwist(nextConfig)
}
return nextConfig
}