-
Notifications
You must be signed in to change notification settings - Fork 3
/
next.config.ts
92 lines (85 loc) · 2.38 KB
/
next.config.ts
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
import NextMDX from '@next/mdx';
import { withSentryConfig } from '@sentry/nextjs';
import CopyPlugin from 'copy-webpack-plugin';
import { readdirSync, statSync } from 'fs';
import setPWA from 'next-pwa';
// @ts-expect-error no official types
import withLess from 'next-with-less';
import RemarkFrontMatter from 'remark-frontmatter';
import RemarkGfm from 'remark-gfm';
import RemarkMdxFrontMatter from 'remark-mdx-frontmatter';
import webpack from 'webpack';
const { NODE_ENV, CI, SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT } =
process.env;
const isDev = NODE_ENV === 'development';
const withMDX = NextMDX({
extension: /\.mdx?$/,
options: {
remarkPlugins: [RemarkFrontMatter, RemarkMdxFrontMatter, RemarkGfm],
},
});
const withPWA = setPWA({
dest: 'public',
register: true,
skipWaiting: true,
disable: isDev,
});
const nextConfig = withPWA(
withLess(
withMDX({
output: CI ? 'standalone' : undefined,
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
transpilePackages: ['@sentry/browser'],
webpack: config => {
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(/^node:/, resource => {
resource.request = resource.request.replace(/^node:/, '');
}),
);
if (
statSync('pages/article', {
throwIfNoEntry: false,
})?.isDirectory() &&
readdirSync('pages/article')[0]
)
config.plugins.push(
new CopyPlugin({
patterns: [
{
from: 'pages/article',
to: 'static/article',
},
],
}),
);
return config;
},
rewrites: async () => ({
beforeFiles: [],
afterFiles: [],
fallback: [
{
source: '/article/:path*',
destination: `/_next/static/article/:path*`,
has: [
{
type: 'header',
key: 'Accept',
value: '.*(image|audio|video|application)/.*',
},
],
},
],
}),
}),
),
);
export default isDev || !SENTRY_AUTH_TOKEN
? nextConfig
: withSentryConfig(nextConfig, {
autoInstrumentServerFunctions: false,
org: SENTRY_ORG,
project: SENTRY_PROJECT,
authToken: SENTRY_AUTH_TOKEN,
silent: true,
});