-
Notifications
You must be signed in to change notification settings - Fork 455
/
next.config.mjs
88 lines (78 loc) · 2.2 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
import nextMDX from '@next/mdx'
import * as crypto from 'crypto'
import * as fsWalk from '@nodelib/fs.walk'
import fs from 'fs'
import path from 'path'
import { recmaPlugins } from './src/mdx/recma.mjs'
import { rehypePlugins } from './src/mdx/rehype.mjs'
import { remarkPlugins } from './src/mdx/remark.mjs'
import withSearch from './src/mdx/search.mjs'
import { withSentryConfig } from '@sentry/nextjs'
const withMDX = nextMDX({
options: {
remarkPlugins,
rehypePlugins,
recmaPlugins,
},
})
const delimiter = '\0'
function getFilesHash(rootPath) {
const shasum = crypto.createHash('sha1')
function processFile(name, content) {
shasum.update(name)
// Add delimiter to hash to prevent collisions between files where the join of the name and content is the same
shasum.update(delimiter)
shasum.update(content)
shasum.update(delimiter)
}
fsWalk.walkSync(rootPath, { stats: true }).forEach(e => {
if (!e.stats.isDirectory()) {
if (e.path.includes('/node_modules/')) return // ignore node_modules which may contain symlinks
const content = fs.readFileSync(e.path, 'utf8')
processFile(e.path, content)
}
})
return shasum.digest('base64')
}
const codeSnippetsDir = path.resolve('./src/code')
/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'mdx'],
basePath: '',
webpack: config => {
const codeFilesHash = getFilesHash(codeSnippetsDir)
config.cache.version = config.cache.version + delimiter + codeFilesHash
return config
},
async rewrites() {
return {
afterFiles: [
{
source: '/ingest/:path*',
destination: 'https://app.posthog.com/:path*',
// BEWARE: setting basePath will break the analytics proxy
},
{ source: '/:path*', destination: '/_404/:path*' },
]
}
}
}
export default withSearch(
withMDX(
withSentryConfig(
nextConfig,
{
silent: true,
org: 'e2b',
project: 'docs',
},
{
widenClientFileUpload: true,
transpileClientSDK: true,
tunnelRoute: '/monitoring',
hideSourceMaps: true,
disableLogger: true,
},
),
),
)