Repository navigation
Expand file tree
/
Copy pathnext.config.mjs
More file actions
84 lines (77 loc) · 2.62 KB
/
Copy pathnext.config.mjs
File metadata and controls
84 lines (77 loc) · 2.62 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
import path from 'node:path'
import { createRequire } from 'node:module'
import nextra from 'nextra'
import remarkSnippetPrompt from './lib/remark-snippet-prompt.mjs'
const require = createRequire(import.meta.url)
const rehypeIcons = require('./lib/rehype-icons')
const remarkBrowserSupport = require('./lib/remark-browser-support')
const withNextra = nextra({
mdxOptions: {
remarkPlugins: [remarkBrowserSupport, remarkSnippetPrompt],
rehypePlugins: [rehypeIcons],
},
})
export default withNextra({
agentRules: false,
async headers() {
return [
{
source: "/:path*",
headers: [
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "SAMEORIGIN" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
],
},
];
},
webpack(config) {
const snippetsDir = path.join(import.meta.dirname, 'snippets')
// Exclude snippets from pre-loaders (React Fast Refresh, etc.)
for (const rule of config.module.rules) {
if (rule.enforce === 'pre') {
rule.exclude = [].concat(rule.exclude || [], snippetsDir)
}
}
// Next 16 keeps its SWC rule outside `oneOf`, so every other rule that handles `.js` must skip
// the snippets, or the loaders rewrite the code before it becomes a string
const rawRule = {
test: /\.js$/,
include: snippetsDir,
resourceQuery: /raw/,
type: 'asset/source',
}
const usesSwc = (rule) =>
[].concat(rule.use || rule.loader || []).some((use) => String(typeof use === 'string' ? use : use?.loader).includes('next-swc-loader'))
const skipSnippets = (rules) => {
for (const rule of rules) {
if (rule.oneOf) skipSnippets(rule.oneOf)
if (usesSwc(rule)) rule.exclude = [].concat(rule.exclude || [], snippetsDir)
}
}
skipSnippets(config.module.rules)
config.module.rules.unshift(rawRule)
return config
},
async redirects() {
return [
{
source: "/Loading/Find-Above-The-Fold-Lazy-Loades-Images",
destination: "/Loading/Find-Above-The-Fold-Lazy-Loaded-Images",
permanent: true,
},
{
source: "/Loading/Inline-Script-Info-and-Size-Including__NEXT_DATA",
destination: "/Loading/SSR-Hydration-Data-Analysis",
permanent: true,
},
{
source: "/CoreWebVitals/LCP-Sub-Parts",
destination: "/CoreWebVitals/LCP-Subparts",
permanent: true,
},
];
},
});
// If you have other Next.js configurations, you can pass them as the parameter:
// module.exports = withNextra({ /* other next.js config */ })