-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathnext.config.js
More file actions
222 lines (208 loc) · 6.03 KB
/
next.config.js
File metadata and controls
222 lines (208 loc) · 6.03 KB
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
/* eslint-env node */
// @ts-check
import nextra from "nextra"
import path from "node:path"
import withLess from "next-with-less"
import nextBundleAnalyzer from "@next/bundle-analyzer"
import fs from "fs"
import rehypeMermaid from "rehype-mermaid"
import withPlaiceholder from "@plaiceholder/next"
import { remarkGraphiQLComment } from "./src/remark-graphiql-comment.js"
import { syntaxHighlightingThemes } from "./src/_design-system/syntax/index.js"
const vercelJSON = JSON.parse(fs.readFileSync("./vercel.json", "utf-8"))
const withNextra = nextra({
autoImportThemeStyle: false,
theme: "nextra-theme-docs",
themeConfig: "./theme.config.tsx",
mdxOptions: {
remarkPlugins: [remarkGraphiQLComment],
rehypePlugins: [mermaidConfig()],
rehypePrettyCodeOptions: {
theme: syntaxHighlightingThemes,
},
},
})
const sep = path.sep === "/" ? "/" : "\\\\"
const ALLOWED_SVG_REGEX = new RegExp(`${sep}icons${sep}.+\\.svg$`)
/**
* @type {import('next').NextConfig}
*/
const config = {
output: undefined,
// reactStrictMode: true, provoke duplicated codemirror editors
webpack(config, { isServer, dev }) {
// #region MDX
const mdxRule = config.module.rules.find(rule => rule.test?.test?.(".mdx"))
if (mdxRule) {
mdxRule.resourceQuery = {
not: /raw/,
}
}
// Instead of transforming MDX, with ?source we can get
// the raw content to process in a Server Component.
config.module.rules.push({
test: /\.mdx$/i,
resourceQuery: /raw/,
type: "asset/source",
})
// #endregion MDX
// #region SVGs
const fileLoaderRule = config.module.rules.find(rule =>
rule.test?.test?.(".svg"),
)
fileLoaderRule.exclude = /\.svg$/i
config.module.rules.push(
{
test: /\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg|txt)$/i,
resourceQuery: /resource/,
type: "asset/resource",
generator: {
filename: "static/media/[name].[hash][ext]",
publicPath: "/_next/",
// Server build outputs to .next/server/, so go up to reach .next/static/
outputPath: [isServer && "../", !dev && "../"]
.filter(Boolean)
.join(""),
},
},
// All .svg from /icons/ and with ?svgr are going to be processed by @svgr/webpack
{
test: ALLOWED_SVG_REGEX,
use: ["@svgr/webpack"],
},
{
test: /\.svg$/i,
exclude: ALLOWED_SVG_REGEX,
resourceQuery: /svgr/,
use: [
{
loader: "@svgr/webpack",
options: {
typescript: true,
svgoConfig: {
plugins: [
{
name: "preset-default",
params: {
overrides: {
minifyStyles: false,
removeViewBox: false,
removeTitle: false,
},
},
},
"removeXMLNS",
"removeXlink",
"prefixIds",
],
},
},
},
],
},
// Otherwise, we use the default file loader
{
...fileLoaderRule,
test: /\.svg$/i,
exclude: ALLOWED_SVG_REGEX,
resourceQuery: {
not: [...fileLoaderRule.resourceQuery.not, /svgr|resource/],
},
},
)
// #endregion SVGs
return config
},
images: {
remotePatterns: [
{
hostname: "avatars.sched.co",
pathname: "**",
},
],
},
env: {
NEXT_PUBLIC_GA_ID:
process.env.NODE_ENV === "production" ? "UA-44373548-16" : "",
},
headers: async () => {
return [
{
source: "/graphql",
headers: [
{
key: "Access-Control-Allow-Origin",
value: "*",
},
{
key: "Access-Control-Allow-Methods",
value: "GET, POST, OPTIONS",
},
{
key: "Access-Control-Allow-Headers",
value: "Content-Type",
},
],
},
]
},
trailingSlash: true,
// Only for local development, skip 200 statusCode due following error:
//
// `statusCode` is not undefined or valid statusCode for route {"source":"/conf/attendee/:path*","destination":"https://graphql-conf-attendee-nextjs.vercel.app/:path*","statusCode":200}
// `statusCode` is not undefined or valid statusCode for route {"source":"/swapi-graphql/:path*","destination":"https://graphql.github.io/swapi-graphql/:path*","statusCode":200}
// Valid redirect statusCode values are 301, 302, 303, 307, 308
redirects: () => vercelJSON.redirects.filter(o => o.statusCode !== 200),
async rewrites() {
return [
{
source: "/swapi-graphql/:path*",
destination: "https://swapi-graphql.netlify.app/:path*",
},
{
source: "/graphql",
destination: "https://swapi-graphql.netlify.app/graphql",
},
]
},
typedRoutes: true,
}
const withBundleAnalyzer = nextBundleAnalyzer({
enabled: process.env.ANALYZE === "true",
})
export default withBundleAnalyzer(
withLess(withNextra(withPlaiceholder(config))),
)
function mermaidConfig() {
return [
rehypeMermaid,
/** @type {import("rehype-mermaid").RehypeMermaidOptions} */ ({
mermaidConfig: {
fontFamily: "var(--font-sans)", // we can't use monospace here because it's way too wide
theme: "null",
look: "classic",
flowchart: {
defaultRenderer: "elk",
padding: 6,
},
themeCSS: `
.node rect {
fill: var(--mermaid-node-fill);
stroke: var(--mermaid-node-stroke);
}
.label text, span {
fill: hsl(var(--color-neu-900));
color: hsl(var(--color-neu-900));
}
.flowchart-link {
stroke: var(--mermaid-arrow);
}
.marker {
stroke: var(--mermaid-arrow);
fill: var(--mermaid-arrow);
}
`,
},
}),
]
}