-
-
Notifications
You must be signed in to change notification settings - Fork 433
/
next.config.js
175 lines (167 loc) · 5.12 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
174
175
/* eslint-disable max-lines */
/* eslint-disable react-func/max-lines-per-function */
/* eslint-disable no-param-reassign */
const path = require('path');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE_BUNDLE === 'true',
});
const { withSentryConfig } = require('@sentry/nextjs');
const withFonts = require('next-fonts');
const withPWA = require('next-pwa');
const nextTranslate = require('next-translate-plugin');
const securityHeaders = require('./configs/SecurityHeaders.js');
const runtimeCaching = require('./pwa-runtime-config.js');
const isDev = process.env.NEXT_PUBLIC_VERCEL_ENV === 'development';
const isProduction = process.env.NEXT_PUBLIC_VERCEL_ENV === 'production';
const withPWAConfig = withPWA({
dest: 'public',
disable: !isProduction,
mode: isProduction ? 'production' : 'development',
publicExcludes: [
'!fonts/**/!(sura_names|ProximaVara)*', // exclude pre-caching all fonts that are not sura_names or ProximaVara
'!icons/**', // exclude all icons
'!images/**/!(background|homepage)*', // don't pre-cache except background.jpg and homepage.png
],
runtimeCaching,
});
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
productionBrowserSourceMaps: true,
swcMinify: true,
images: {
formats: ['image/avif', 'image/webp'],
domains: [
'cdn.qurancdn.com',
'static.qurancdn.com',
'vercel.com',
'now.sh',
'quran.com',
'images.quran.com',
],
},
webpack: (webpackConfig) => {
webpackConfig.resolve = {
...webpackConfig.resolve,
alias: {
...webpackConfig.resolve.alias,
'audio-worklet': path.resolve(__dirname, 'src/audioInput/audio-worklet.ts'),
},
};
webpackConfig.module.parser = {
...webpackConfig.module.parser,
javascript: {
worker: ['AudioWorklet from audio-worklet'],
},
};
webpackConfig.module.rules.push({
test: /\.svg$/i,
issuer: {
and: [/\.(js|ts)x?$/],
},
use: [
{
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
],
},
},
},
],
});
return webpackConfig;
},
headers: async () => {
return isDev
? []
: [
{
source: '/:route*', // apply security rules to all routes.
headers: securityHeaders,
},
{
source: '/fonts/:font*', // match wildcard fonts' path which will match any font file on any level under /fonts.
headers: [
{
key: 'cache-control',
value: 'public, max-age=31536000, immutable', // Max-age is 1 year. immutable indicates that the font will not change over the expiry time.
},
],
},
{
source: '/images/:image*', // match wildcard images' path which will match any image file on any level under /images.
headers: [
{
key: 'cache-control',
value: 'public, max-age=604800, immutable', // Max-age is 1 week. immutable indicates that the image will not change over the expiry time.
},
],
},
{
source: '/icons/:icon*', // match wildcard icons' path which will match any icon file on any level under /icons.
headers: [
{
key: 'cache-control',
value: 'public, max-age=604800, immutable', // Max-age is 1 week. immutable indicates that the icon will not change over the expiry time.
},
],
},
];
},
redirects: async () => [
{
source: '/:surah/:from(\\d{1,})\\::to(\\d{1,})', // 1/2:3 => 1/2-3
destination: '/:surah/:from-:to',
permanent: true,
},
{
source: '/:surah\\::from(\\d{1,})\\::to(\\d{1,})', // 1:2:3 => 1/2-3
destination: '/:surah/:from-:to',
permanent: true,
},
{
source: '/:surah(\\d{1,})-:from\\::to', // 1-2:3 => 1/2-3
destination: '/:surah/:from-:to',
permanent: true,
},
{
source: '/:surah(\\d{1,})-:from(\\d{1,})-:to(\\d{1,})', // 1-2-3 => 1/2-3
destination: '/:surah/:from-:to',
permanent: true,
},
{
source: '/:surah(\\d{1,})\\::from(\\d{1,})-:to(\\d{1,})', // 1:2-3 => 1/2-3
destination: '/:surah/:from-:to',
permanent: true,
},
],
compiler: {
removeConsole: !isDev,
},
};
// Apply plugins
const configWithPlugins = withBundleAnalyzer(withFonts(nextTranslate(withPWAConfig(nextConfig))));
// Apply Sentry configuration
module.exports = withSentryConfig(
configWithPlugins,
{
silent: true,
},
{
hideSourceMaps: !isDev,
// Additional config options for the Sentry Webpack plugin
// ... (any additional Sentry options)
},
);