-
Notifications
You must be signed in to change notification settings - Fork 1
/
next.config.mjs
129 lines (118 loc) · 4.45 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
// @ts-check
import { withSentryConfig } from "@sentry/nextjs";
// Adding NEXT_PUBLIC_ makes environment variables available inside Next.js client.
// We don’t use the prefix outside Next.js code to make app setup less bulky and
// to avoid unnecessary breaking changes in it.
process.env.NEXT_PUBLIC_COMMENTS_ARE_PAUSED = process.env.COMMENTS_ARE_PAUSED;
process.env.NEXT_PUBLIC_DJANGO_BASE_URL = process.env.DJANGO_BASE_URL;
process.env.NEXT_PUBLIC_DJANGO_CONTENT_FALLBACK =
process.env.DJANGO_CONTENT_FALLBACK;
process.env.NEXT_PUBLIC_SENTRY_DSN = process.env.SENTRY_DSN;
process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT = process.env.SENTRY_ENVIRONMENT;
/**
* @type Omit<import("next").NextConfig, "webpack">
* @todo Remove Omit<> when mismatch between Next Config and Sentry config is resolved
*/
const nextConfig = {
compiler: {
styledComponents: true,
},
productionBrowserSourceMaps: true,
reactStrictMode: true,
swcMinify: true,
// We call linters in GitHub Actions for all pull requests. By not linting
// again during `next build`, we save CI minutes and unlock more feedback.
// For local checks, run `yarn lint`.
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
redirects: async () => [
// This redirect was added before the public release to minimise SSR.
// @todo Remove after 2022-03-01
{
source: "/iframes/comments/:slug",
destination: "/iframes/comments?accident-id=:slug",
permanent: true,
},
// Data dumps like /media/opendata/penzenskaia-oblast.geojson are too large to be
// proxied by Netlify via fallback rewrites. Direct links are redirected to Django.
...(process.env.DJANGO_BASE_URL
? [
{
source: "/media/opendata/:slug*",
destination: `${process.env.DJANGO_BASE_URL}/media/opendata/:slug*`,
permanent: false,
},
]
: []),
],
rewrites: () => ({
beforeFiles: [
{
source: "/robots.txt",
destination: "/api/rewrites/robots",
},
],
// Incremental adoption of Next.js (content form Django is served as fallback)
// https://nextjs.org/docs/api-reference/next.config.js/rewrites#incremental-adoption-of-nextjs
// @todo Remove once all web pages are migrated to React
fallback:
process.env.DJANGO_BASE_URL &&
process.env.DJANGO_CONTENT_FALLBACK === "true"
? [
// Serve known pages with a local LRU cache and HTML modifications while proxying
...[
"/",
"/blog",
"/blog/vision-zero",
"/blog/proektirovanie-bezopasnykh-ulits",
"/blog/zachem-nuzhny-dannye-dtp-i-chto-s",
"/donate",
"/opendata",
"/pages/about",
"/pages/dashboard",
].map((source) => ({
source,
destination: "/api/rewrites/proxy-django-html-page",
})),
{
// Fetch sitemap from Django until sitemap generation is moved to Next
source: "/sitemap.xml",
destination: `${process.env.DJANGO_BASE_URL}/sitemap.xml`,
},
{
source: "/sitemap-dtp.xml",
destination: `${process.env.DJANGO_BASE_URL}/sitemap-dtp.xml`,
},
{
// Add trailing slash to page-like paths (/hello/world) to avoid infinite redirects
source: "/:path([^\\.]+)*",
destination: `${process.env.DJANGO_BASE_URL}/:path*/`,
},
{
// Add trailing slash to root file-like paths (/hello.txt), also to avoid infinite
// redirects (this is needed because of a special `old_redirect` rule in Django)
source: "/:path",
destination: `${process.env.DJANGO_BASE_URL}/:path/`,
},
{
// Do not add trailing slash to all other file-like paths (/hello/world.txt)
source: "/:path*",
destination: `${process.env.DJANGO_BASE_URL}/:path*`,
},
]
: [],
}),
};
/**
* @type Partial<import("@sentry/nextjs/src/config/types").SentryWebpackPluginOptions>
*/
const sentryWebpackPluginOptions = {
dryRun: !process.env.SENTRY_AUTH_TOKEN,
silent: true,
deploy: {
env: process.env.SENTRY_ENVIRONMENT,
},
};
export default process.env.SENTRY_DSN
? withSentryConfig(nextConfig, sentryWebpackPluginOptions)
: nextConfig;