forked from graphql/graphql.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
132 lines (123 loc) · 4.19 KB
/
next.config.js
File metadata and controls
132 lines (123 loc) · 4.19 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
/* eslint-env node */
import nextra from "nextra"
import path from "node:path"
import withLess from "next-with-less"
import { remarkGraphiQLComment } from "./src/remark-graphiql-comment.js"
import fs from "fs"
const vercelJSON = JSON.parse(fs.readFileSync("./vercel.json", "utf-8"))
const withNextra = nextra({
theme: "nextra-theme-docs",
themeConfig: "./theme.config.tsx",
mdxOptions: {
remarkPlugins: [remarkGraphiQLComment],
},
})
const sep = path.sep === "/" ? "/" : "\\\\"
const ALLOWED_SVG_REGEX = new RegExp(`${sep}icons${sep}.+\\.svg$`)
/**
* @type {import('next').NextConfig}
*/
export default withLess(
withNextra({
// reactStrictMode: true, provoke duplicated codemirror editors
webpack(config) {
const fileLoaderRule = config.module.rules.find(rule =>
rule.test?.test?.(".svg"),
)
fileLoaderRule.exclude = /\.svg$/i
config.module.rules.push(
// 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: {
dimensions: false, // **adds** viewBox.
},
},
],
},
// Otherwise, we use the default file loader
{
...fileLoaderRule,
test: /\.svg$/i,
exclude: ALLOWED_SVG_REGEX,
resourceQuery: {
not: [...fileLoaderRule.resourceQuery.not, /svgr/],
},
},
)
return config
},
output: "export",
images: {
loader: "custom",
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
},
transpilePackages: ["next-image-export-optimizer"],
env: {
nextImageExportOptimizer_imageFolderPath: "public/images",
nextImageExportOptimizer_exportFolderPath: "out",
nextImageExportOptimizer_quality: "75",
nextImageExportOptimizer_storePicturesInWEBP: "true",
nextImageExportOptimizer_exportFolderName: "nextImageExportOptimizer",
// If you do not want to use blurry placeholder images, then you can set
// nextImageExportOptimizer_generateAndUseBlurImages to false and pass
// `placeholder="empty"` to all <ExportedImage> components.
nextImageExportOptimizer_generateAndUseBlurImages: "true",
// If you want to cache the remote images, you can set the time to live of the cache in seconds.
// The default value is 0 seconds.
nextImageExportOptimizer_remoteImageCacheTTL: "0",
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",
},
]
},
}),
)