-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
101 lines (80 loc) · 2.94 KB
/
next.config.mjs
File metadata and controls
101 lines (80 loc) · 2.94 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
import { spawnSync } from "node:child_process";
import withBundleAnalyzer from "@next/bundle-analyzer";
import withSerwistInit from "@serwist/next";
import { withSentryConfig } from "@sentry/nextjs";
const withAnalyzer = withBundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});
const isGitHubPages = process.env.GITHUB_PAGES === "true";
const basePath = isGitHubPages ? "/bonnie-wee-plot" : "";
// Get git revision for cache busting, fallback to random UUID
const getRevision = () => {
try {
const result = spawnSync("git", ["rev-parse", "HEAD"], { encoding: "utf-8" });
return result.stdout?.trim() || crypto.randomUUID();
} catch {
return crypto.randomUUID();
}
};
const withSerwist = withSerwistInit({
swSrc: "src/app/sw.ts",
swDest: "public/sw.js",
additionalPrecacheEntries: [{ url: `${basePath}/~offline`, revision: getRevision() }],
// Disable in development to avoid cache issues
disable: process.env.NODE_ENV === "development",
});
/** @type {import('next').NextConfig} */
const nextConfig = {
// Conditionally enable static export for GitHub Pages
...(isGitHubPages && { output: "export" }),
// Base path for GitHub Pages (repo name)
basePath,
// Asset prefix for GitHub Pages
assetPrefix: isGitHubPages ? "/bonnie-wee-plot/" : "",
// Image configuration — only disable optimization for static export (GitHub Pages)
images: {
unoptimized: isGitHubPages,
remotePatterns: [
{
protocol: "https",
hostname: "images.unsplash.com",
},
],
},
// Trailing slash for static hosting compatibility (GitHub Pages)
trailingSlash: isGitHubPages,
// Enable Turbopack (Next.js 16+ default) - empty config silences webpack warning
turbopack: {},
// Server Actions configuration (for non-static builds)
...(!isGitHubPages && {
experimental: {
serverActions: {
bodySizeLimit: "10mb",
},
},
}),
};
// Sentry configuration for source maps and error tracking
const sentryConfig = {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
// Only upload source maps in production builds with Sentry configured
silent: !process.env.SENTRY_DSN,
// Upload source maps to Sentry for production debugging
widenClientFileUpload: true,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,
// Prevents source map comments in production
hideSourceMaps: true,
// Automatically instrument client-side routes
automaticVercelMonitors: false,
};
// Apply Serwist first, then Sentry
const configWithSerwist = withSerwist(nextConfig);
// Only apply Sentry wrapper if DSN is configured (skip for GitHub Pages static export)
const finalConfig = process.env.SENTRY_DSN && !isGitHubPages
? withSentryConfig(configWithSerwist, sentryConfig)
: configWithSerwist;
export default withAnalyzer(finalConfig);