-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathnext.config.mjs
126 lines (115 loc) · 3.8 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
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
import NextBundleAnalyzer from "@next/bundle-analyzer";
import createMDX from "@next/mdx";
import { withSentryConfig } from "@sentry/nextjs";
import createJiti from "jiti";
import createNextIntlPlugin from "next-intl/plugin";
import { fileURLToPath } from "node:url";
import path from "path";
// TODO: After the stable version of Million Lint is released, consider using it to further enhance performance.
// Currently, there are bugs in it that can cause the popover component not work.
// validate environment variables during build
const jiti = createJiti(fileURLToPath(import.meta.url));
jiti("./src/lib/env");
const isDev = process.env.NODE_ENV === "development";
const isCN = /\.cn(:3000)?$/.test(process.env.NEXT_PUBLIC_APP_URL);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/** @type {import("next").NextConfig} */
const nextConfig = {
// not affect auto batching, but it may cause console.log output three times: https://github.com/facebook/react/issues/24570
reactStrictMode: true,
swcMinify: true,
poweredByHeader: false,
output: isCN ? "standalone" : undefined,
pageExtensions: ["js", "jsx", "md", "mdx", "ts", "tsx"],
experimental: {
serverActions: {
allowedOrigins: ["json4u.com", "*.json4u.com", "json4u.cn", "*.json4u.cn"],
},
optimizePackageImports: [
"react-use",
"@next/mdx",
"lodash-es",
"lucide-react",
"monaco-editor",
"@xyflow/react",
"@supabase/auth-ui-react",
"@supabase/auth-ui-shared",
"@supabase/supabase-js",
"@sentry/react",
"@sentry/nextjs",
"@sentry/utils",
"zod",
"usehooks-ts",
],
},
webpack(config, { dev, isServer, webpack }) {
if (!isServer) {
config.resolve.fallback = { fs: false };
config.resolve.alias = {
...config.resolve.alias,
"@": __dirname,
};
config.output.webassemblyModuleFilename = "static/wasm/[modulehash].wasm";
// can't use experiments
// config.experiments = { asyncWebAssembly: true };
config.plugins.push(
new webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
__SENTRY_TRACING__: false,
__RRWEB_EXCLUDE_IFRAME__: true,
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
}),
);
}
return config;
},
};
const withNextIntl = createNextIntlPlugin("./src/i18n/request.tsx");
const withMDX = createMDX({});
const withBundleAnalyzer = NextBundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});
const config = withBundleAnalyzer(withNextIntl(withMDX(nextConfig)));
const enableSourceMap = !!process.env.SENTRY_AUTH_TOKEN;
export default withSentryConfig(config, {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
org: "loggerhead",
project: "json4u",
enable: !isDev,
authToken: enableSourceMap ? process.env.SENTRY_AUTH_TOKEN : undefined,
// avoid build failed when miss SENTRY_AUTH_TOKEN
sourcemaps: {
disable: !enableSourceMap,
},
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
ignore: [
"__tests__",
"e2e",
"dist",
"node_modules",
"public",
".next",
".vercel",
".vscode",
".idea",
".gitignore",
".DS_Store",
"*.log",
".env.*",
"sentry.*.config.js",
"README.md",
"yarn.lock",
],
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Transpiles SDK to be compatible with IE11 (increases bundle size)
transpileClientSDK: false,
telemetry: false,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
});