-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnext.config.js
106 lines (93 loc) · 2.38 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const { withSentryConfig } = require('@sentry/nextjs');
let commitHash = 'no-git-commit';
try {
commitHash = process.env.COMMIT_SHA || 'no-git-commit';
} catch (error) {
// eslint-disable-next-line no-console
console.error(`Get git commit hash failed.`);
}
const withTranspileModules = require('next-transpile-modules')(['echarts']);
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
openAnalyzer: true,
});
const webpack = (config, options) => {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
return config;
};
const _getPublicEnv = (prefix) => {
const envs = process.env;
const res = {};
Object.keys(envs).forEach((k) => {
if (k.startsWith(prefix)) {
res[k] = envs[k];
}
});
return res;
};
const assetPrefix = process.env.NEXT_PUBLIC_STATIC_HOST || '';
/**
* @type {import('@sentry/nextjs').SentryWebpackPluginOptions}
*/
const sentryWebpackPluginOptions = {
silent: true, // Suppresses all logs
org: 'nodereal-sentry',
project: 'dcellar-ui',
authToken: '9e42bc70fd9f45e7a3aaac568e0204a60e734f6ce56d4384af57bedf72e0fcc8',
};
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
headers: async () => [
{
// cache public folder assets (default max-age: 0).
source: `${assetPrefix}/:public(fonts|images|wasm|zk-crypto|js)/:path*`,
locale: false,
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000',
},
],
},
],
// https://github.com/vercel/next.js/issues/35822
// render twice & the memory usage of the wasm instance will also be impacted.
reactStrictMode: false,
distDir: '.next',
webpack,
assetPrefix: '',
pageExtensions: ['mdx', 'jsx', 'js', 'ts', 'tsx'],
generateBuildId: async () => {
return commitHash;
},
publicRuntimeConfig: {
..._getPublicEnv('NEXT_PUBLIC_'),
},
serverRuntimeConfig: {
..._getPublicEnv('NEXT_PRIVATE_'),
},
sentry: {
hideSourceMaps: true,
},
experimental: {
instrumentationHook: true,
},
compiler: {
emotion: true,
removeConsole:
process.env.NODE_ENV === 'production'
? {
exclude: ['error', 'warn'],
}
: false,
},
};
module.exports = withSentryConfig(
withBundleAnalyzer(withTranspileModules(nextConfig)),
sentryWebpackPluginOptions,
);