-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathnext.config.js
53 lines (47 loc) · 1.54 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
import nextConst from 'next/constants.js';
import { checkEnvs, tryLoadParentGitRepoEnv } from './scripts/utils.mjs';
async function tryLoadCodeInspector() {
if (process.env.NODE_ENV !== 'development') return null
const { codeInspectorPlugin } = await import('code-inspector-plugin');
return codeInspectorPlugin({
bundler: 'webpack',
hideDomPathAttr: true,
editor: process.env.CODE_INSPECTOR_EDITOR || undefined
})
}
export default async function setup(phase) {
tryLoadParentGitRepoEnv()
if (phase === nextConst.PHASE_DEVELOPMENT_SERVER || phase === nextConst.PHASE_PRODUCTION_SERVER) {
checkEnvs()
}
const domainHost = new URL(process.env.AUTH_URL || 'http://localhost').host
const codeInspector = await tryLoadCodeInspector()
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: '*.iconify.design',
pathname: '**',
},
],
dangerouslyAllowSVG: true,
},
webpack: (config, { webpack, nextRuntime }) => {
codeInspector && config.plugins.push(codeInspector)
// https://github.com/vercel/next.js/discussions/39705
// fix: edge 环境无法加载环境变量
if (nextRuntime === 'edge') {
config.plugins.push(new webpack.DefinePlugin({
"process.env.AUTH_SECRET": JSON.stringify(process.env.AUTH_SECRET),
}))
}
return config
},
experimental: {
serverActions: { allowedOrigins: [domainHost] }
}
}
return nextConfig
}