forked from OperationCode/front-end
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
136 lines (123 loc) · 3.2 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
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const withMDX = require('@next/mdx')({
extension: /\.mdx$/,
});
const svgoConfig = require('./common/config/svgo');
const nextConfig = withBundleAnalyzer({
// For Vercel
// see: https://vercel.com/guides/deploying-nextjs-with-vercel
target: 'serverless',
experimental: {
productionBrowserSourceMaps: true,
scrollRestoration: true,
},
/** @see https://nextjs.org/docs/api-reference/next.config.js/rewrites */
async rewrites() {
return [
{
source: '/media',
destination: '/branding',
},
{
source: '/privacy',
destination: 'https://www.iubenda.com/privacy-policy/8174861',
},
];
},
/** @see https://nextjs.org/docs/api-reference/next.config.js/redirects */
async redirects() {
return [
{
source: '/swag',
destination: 'https://operationcode.threadless.com/',
permanent: true,
},
{
source: '/store',
destination: 'https://operationcode.threadless.com/',
permanent: true,
},
{
source: '/shop',
destination: 'https://operationcode.threadless.com/',
permanent: true,
},
];
},
/** @see https://nextjs.org/docs/api-reference/next.config.js/headers */
async headers() {
return [
{
source: '/_next/static/([^/]+/pages|chunks|runtime|css|fonts)/(.+)',
headers: [
{
key: 'cache-control',
value: 'max-age=31536000',
},
],
},
{
source: '/(favicon.ico|robots.txt|manifest.json|humans.txt|sitemap.xml|sitemap.xsl)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=0, must-revalidate',
},
],
},
];
},
webpack: config => {
// Fixes npm packages that depend on `fs` module
// eslint-disable-next-line no-param-reassign
config.node = { fs: 'empty' };
config.module.rules.push(
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
svgoConfig,
},
},
],
},
{
test: /\.(jpe?g|png|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
fallback: {
loader: 'file-loader',
options: {
publicPath: '/_next/static/images',
outputPath: 'static/images',
},
},
publicPath: '/_next/',
outputPath: 'static/images/',
name: '[name]-[hash].[ext]',
},
},
],
},
);
// Add polyfills
const originalEntry = config.entry;
// eslint-disable-next-line no-param-reassign
config.entry = async () => {
const entries = await originalEntry();
if (entries['main.js'] && !entries['main.js'].includes('./polyfills.js')) {
entries['main.js'].unshift('./polyfills.js');
}
return entries;
};
return config;
},
});
module.exports = withMDX(nextConfig);