-
Notifications
You must be signed in to change notification settings - Fork 7
/
next.config.js
173 lines (162 loc) · 5.39 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
165
166
167
168
169
170
171
172
173
// next.config.js
// ==============
// https://nextjs.org/docs/api-reference/next.config.js/introduction
//
// IMPORTANT: next.config.js is not parsed by Webpack, Babel, or Typescript.
// Avoid language features that are not available in your target Node.js version.
// Do not change the file extenstion to .ts.
//
// Have fun! 🚀
const { wordPressEndpoint } = require( './vip.config' );
// Next.js currently doesn't have a good way to match all paths including the
// root, so we need to use a special regex path.
const allPathsIncludingRoot = '/:path*{/}?';
module.exports = {
// Base path
// =========
// https://nextjs.org/docs/api-reference/next.config.js/basepath
//
// Setting a base path is not recommend because it prevents us from serving
// files at the root, such as 'robots.txt'.
basePath: '',
// ESLint
// ======
// https://nextjs.org/docs/basic-features/eslint
eslint: {
dirs: [
'components',
'graphql',
'lib',
'pages',
'server',
],
// Warning: Dangerously allow production builds to successfully complete even
// if your project has ESLint errors. This allows us to keep ESLint as a
// dev dependency.
ignoreDuringBuilds: true,
},
// Experimental options
// ====================
// https://github.com/vercel/next.js/blob/canary/packages/next/server/config-shared.ts
experimental: {
// Disable writing to disk in ISR mode. VIP file system is read only, so this
// avoids generating lots of noisy errors in the logs. ISR artifacts are
// still cached in-memory.
isrFlushToDisk: false,
},
// Response headers
// ================
// https://nextjs.org/docs/api-reference/next.config.js/headers
async headers() {
return [
// The default Cache-Control response headers provided by Next.js out of
// the box do not work well with VIP's edge cache. This config rule gives
// every non-static path a max-age of five minutes, providing much better
// protection from traffic spikes and improving performance overall.
//
// Please do not lower this max-age without talking to VIP. :)
//
// This header is overwritten when using static-while-revalidate, so please
// do not set revalidate lower than 300 without talking to VIP. :) :)
{
source: allPathsIncludingRoot,
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=300',
},
],
},
]
},
// React strict mode
// =================
// https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode
//
// Be prepared for future breaking changes in React.
reactStrictMode: true,
// Redirects
// =========
// https://nextjs.org/docs/api-reference/next.config.js/redirects
async redirects() {
return [
{
source: allPathsIncludingRoot,
destination: `${ wordPressEndpoint }/:path*`,
has: [
{
type: 'query',
key: 'preview',
value: 'true',
},
],
permanent: false,
},
{
source: allPathsIncludingRoot,
destination: `${ wordPressEndpoint }/:path*`,
has: [
{
type: 'query',
key: 'p',
},
],
permanent: false,
},
];
},
// Rewrites
// ========
// https://nextjs.org/docs/api-reference/next.config.js/rewrites
async rewrites() {
return {
// Since we have a fallback route defined at the root (`[[...slug]].tsx`),
// we must apply rewrites before any Next.js routing.
beforeFiles: [
// Dynamically serve robots.txt.
{
source: '/robots.txt',
destination: '/api/robots',
},
],
};
},
// Trailing slash
// ==============
// https://nextjs.org/docs/api-reference/next.config.js/trailing-slash
//
// Setting this value to `true` is not recommended at this time.
//
// Next.js has support for trailing slashes, but its implementation is buggy
// and makes it difficult to satisfy VIP's required health check endpoint --
// which cannot support a trailing slash. Simply changing this value to `true`
// will result in failed health checks and deploys on VIP.
//
// If your application requires trailing slashes, you will need to implement a
// custom server so that the cache healthcheck endpoint is handled before
// sending the request to Next.js. For an example, see this branch and the
// Next.js documentation.
//
// https://github.com/Automattic/vip-go-nextjs-skeleton/tree/example/custom-server-trailing-slash
// https://nextjs.org/docs/advanced-features/custom-server
trailingSlash: false,
// Image Optimization
// ==================
// https://nextjs.org/docs/basic-features/image-optimization
//
// The next/image, is an extension of the HTML <img> element, evolved for
// the modern web. It includes a variety of built-in performance
// optimizations to help you achieve good Core Web Vitals.
images: {
// If you know the expected device widths of your users, you can specify a
// list of device width breakpoints using the deviceSizes property here.
// These widths are used when the next/image component uses layout="responsive"
// or layout="fill" to ensure the correct image is served for user's device.
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
// The reason there are two separate lists is that imageSizes is only used
// for images which provide a sizes prop, which indicates that the image
// is less than the full width of the screen. Therefore, the sizes in
// imageSizes should all be smaller than the smallest size in deviceSizes.
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
},
};