forked from pancakeswap/pancake-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.mjs
224 lines (217 loc) · 6.04 KB
/
next.config.mjs
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* eslint-disable @typescript-eslint/no-var-requires */
import BundleAnalyzer from '@next/bundle-analyzer'
import { withWebSecurityHeaders } from '@pancakeswap/next-config/withWebSecurityHeaders'
import smartRouterPkgs from '@pancakeswap/smart-router/package.json' assert { type: 'json' }
import { withSentryConfig } from '@sentry/nextjs'
import { createVanillaExtractPlugin } from '@vanilla-extract/next-plugin'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const withBundleAnalyzer = BundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
})
const withVanillaExtract = createVanillaExtractPlugin()
const sentryWebpackPluginOptions =
process.env.VERCEL_ENV === 'production'
? {
// Additional config options for 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
silent: false, // Logging when deploying to check if there is any problem
validate: true,
hideSourceMaps: false,
// https://github.com/getsentry/sentry-webpack-plugin#options.
}
: {
hideSourceMaps: false,
silent: true, // Suppresses all logs
dryRun: !process.env.SENTRY_AUTH_TOKEN,
}
const workerDeps = Object.keys(smartRouterPkgs.dependencies)
.map((d) => d.replace('@pancakeswap/', 'packages/'))
.concat(['/packages/smart-router/', '/packages/swap-sdk/', '/packages/token-lists/'])
/** @type {import('next').NextConfig} */
const config = {
typescript: {
tsconfigPath: 'tsconfig.build.json',
},
compiler: {
styledComponents: true,
},
experimental: {
scrollRestoration: true,
fallbackNodePolyfills: false,
outputFileTracingRoot: path.join(__dirname, '../../'),
outputFileTracingExcludes: {
'*': [],
},
},
transpilePackages: [
'@pancakeswap/farms',
'@pancakeswap/position-managers',
'@pancakeswap/localization',
'@pancakeswap/hooks',
'@pancakeswap/utils',
'@pancakeswap/widgets-internal',
'@pancakeswap/ifos',
'@pancakeswap/gauges',
],
reactStrictMode: true,
swcMinify: true,
images: {
contentDispositionType: 'attachment',
remotePatterns: [
{
protocol: 'https',
hostname: 'static-nft.pancakeswap.com',
pathname: '/mainnet/**',
},
],
},
async rewrites() {
return [
{
source: '/info/token/:address',
destination: '/info/tokens/:address',
},
{
source: '/info/pool/:address',
destination: '/info/pools/:address',
},
]
},
async headers() {
return [
{
source: '/favicon.ico',
headers: [
{
key: 'Cache-Control',
value: 'public, immutable, max-age=31536000',
},
],
},
{
source: '/logo.png',
headers: [
{
key: 'Cache-Control',
value: 'public, immutable, max-age=31536000',
},
],
},
{
source: '/images/:all*',
headers: [
{
key: 'Cache-Control',
value: 'public, immutable, max-age=31536000',
},
],
},
{
source: '/images/tokens/:all*',
headers: [
{
key: 'Cache-Control',
value: 'public, immutable, max-age=604800',
},
],
},
]
},
async redirects() {
return [
{
source: '/send',
destination: '/swap',
permanent: true,
},
{
source: '/swap/:outputCurrency',
destination: '/swap?outputCurrency=:outputCurrency',
permanent: true,
},
{
source: '/create/:currency*',
destination: '/add/:currency*',
permanent: true,
},
{
source: '/farms/archived',
destination: '/farms/history',
permanent: true,
},
{
source: '/pool',
destination: '/liquidity',
permanent: true,
},
{
source: '/staking',
destination: '/pools',
permanent: true,
},
{
source: '/syrup',
destination: '/pools',
permanent: true,
},
{
source: '/collectibles',
destination: '/nfts',
permanent: true,
},
{
source: '/info/pools',
destination: '/info/pairs',
permanent: true,
},
{
source: '/info/pools/:address',
destination: '/info/pairs/:address',
permanent: true,
},
{
source: '/api/v3/:chainId/farms/liquidity/:address',
destination: 'https://farms-api.pancakeswap.com/v3/:chainId/liquidity/:address',
permanent: false,
},
{
source: '/images/tokens/:address',
destination: 'https://tokens.pancakeswap.finance/images/:address',
permanent: false,
},
]
},
webpack: (webpackConfig, { webpack, isServer }) => {
// tree shake sentry tracing
webpackConfig.plugins.push(
new webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: false,
}),
)
if (!isServer && webpackConfig.optimization.splitChunks) {
// webpack doesn't understand worker deps on quote worker, so we need to manually add them
// https://github.com/webpack/webpack/issues/16895
// eslint-disable-next-line no-param-reassign
webpackConfig.optimization.splitChunks.cacheGroups.workerChunks = {
chunks: 'all',
test(module) {
const resource = module.nameForCondition?.() ?? ''
return resource ? workerDeps.some((d) => resource.includes(d)) : false
},
priority: 31,
name: 'worker-chunks',
reuseExistingChunk: true,
}
}
return webpackConfig
},
}
export default withBundleAnalyzer(
withVanillaExtract(withSentryConfig(withWebSecurityHeaders(config)), sentryWebpackPluginOptions),
)