-
Notifications
You must be signed in to change notification settings - Fork 26
/
next.config.js
164 lines (140 loc) · 4.68 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
let nextConfig;
const path = require('path');
const { withSentryConfig } = require('@sentry/nextjs');
const { i18n } = require('./next-i18next.config');
const os = require('os');
const platform = os.platform();
const outputStandaloneEnable = platform === 'linux';
const unifyNodeModules = (names) =>
names.reduce(
(acc, name) => ({
...acc,
[name]: path.resolve(`./node_modules/${name}`),
}),
{}
);
/**
* @type {import('next').NextConfig}
**/
const config = {
i18n,
pageExtensions: ['page.js', 'page.jsx', 'page.tsx'],
images: {
domains: [
'localhost',
'tidb.net',
'contributor.tidb.io',
'cms.tidb.net',
'img3.pingcap.com',
'i0.hdslb.com',
'i1.hdslb.com',
'i2.hdslb.com',
],
},
styledComponents: true,
/**
* because it is an open-source project,
* so we could allow next.js to build the source-maps files and publish them to the production environment,
* it will help us debug more efficiently
*/
productionBrowserSourceMaps: true,
/**
* using the Next.js compiler for minification. This is 7x faster than Terser.
*/
swcMinify: true,
/**
* for building the docker image
*/
experimental: {
outputStandalone: outputStandaloneEnable,
},
// https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
webpack: (config, options) => {
const { alias } = config.resolve;
config.resolve.alias = {
...alias,
...unifyNodeModules(['antd', 'polished', 'ramda', 'react', 'react-dom', 'react-is', 'styled-components']),
// Make sure we will build directly from the source code for internal consumers,
// which gives us an instant reaction if anything updates
'@tidb-community/common': path.resolve('./packages/common/src'),
'@tidb-community/datasource': path.resolve('./packages/datasource/src'),
'@tidb-community/tracking-script': path.resolve('./packages/trackingScript/src'),
'@tidb-community/ui': path.resolve('./packages/ui/src'),
'@': path.resolve('./'),
'~': path.resolve('./src'),
'@pingcap-inc/tidb-community-editor/dist/style.css': path.resolve(
'./node_modules/@pingcap-inc/tidb-community-editor/dist/style.css'
),
'@pingcap-inc/tidb-community-editor': path.resolve(
'./node_modules/@pingcap-inc/tidb-community-editor/dist/index.full-es.js'
),
};
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
return config;
},
async rewrites() {
return [{ source: '/next-api/:path*', destination: '/api/:path*' }];
},
//TODO: move the redirection rules to the {path}/index.tsx file using getStaticProps(context).
// it will be high cohesion and easily to maintenance
async redirects() {
return [
{
source: '/u/:username',
destination: '/u/:username/answer',
permanent: false,
},
{
source: '/u/:username/favorite',
destination: '/u/:username/favorite/article',
permanent: false,
},
];
},
};
if (process.env.ENABLE_SENTRY === 'true') {
// sentry will set dryRun automatically in development so nothing will be uploaded
const SentryWebpackPluginOptions = {
// Additional config options fsor the Sentry Webpack plugin. Keep in mind that
// the following options are set automatically, and overriding them is not
// recommended:
// release, url, org, project, authToken, configFile, stripPrefix,
// urlPrefix, include, ignore
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
silent: process.env.NODE_ENV === 'development',
release: process.env.SENTRY_RELEASE,
setCommits: {
auto: true,
ignoreMissing: true,
ignoreEmpty: true,
},
};
nextConfig = withSentryConfig(config, SentryWebpackPluginOptions);
} else {
nextConfig = config;
}
if (process.env.NEXT_PUBLIC_CDN_URL) {
nextConfig.assetPrefix = process.env.NEXT_PUBLIC_CDN_URL;
}
// for transpiling all ESM @fullcalendar/* packages
// also, for piping fullcalendar thru babel (to learn why, see babel.config.js)
const withTM = require('next-transpile-modules')([
// Need to specify all @fullcalendar modules separately
// with next-transpile-modules^6.x …
// refer to https://github.com/fullcalendar/fullcalendar-example-projects/pull/19 for more detail
'@fullcalendar/core',
'@fullcalendar/react',
'@fullcalendar/common',
'@fullcalendar/daygrid',
]);
const finalConfig = withTM(nextConfig);
if (process.env.ANALYZE === 'true') {
module.exports = require('@next/bundle-analyzer')({ enabled: true })(finalConfig);
} else {
module.exports = finalConfig;
}
// module.exports = nextConfig