-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathnext.config.ts
More file actions
115 lines (99 loc) · 3.26 KB
/
next.config.ts
File metadata and controls
115 lines (99 loc) · 3.26 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import type { NextConfig } from 'next';
import { PHASE_PRODUCTION_BUILD } from 'next/constants';
const nextConfig = (phase: string): NextConfig => {
// Determine if we should use basePath (production build, not Surge preview)
const isProductionBuild = phase === PHASE_PRODUCTION_BUILD;
const isSurgePreview = process.env.SURGE_PREVIEW === 'true';
const shouldUseBasePath = isProductionBuild && !isSurgePreview;
const basePath = shouldUseBasePath ? '/github-profile-readme-generator' : '';
return {
// Output as static site for GitHub Pages
output: 'export',
// Base path for GitHub Pages (only for production builds, not Surge previews)
basePath,
// Asset prefix to ensure all assets use the correct path
assetPrefix: shouldUseBasePath ? '/github-profile-readme-generator/' : '',
// Environment variables
env: {
NEXT_PUBLIC_BASE_PATH: basePath,
},
// Image optimization for static export
images: {
unoptimized: true, // Required for static export
},
// Trailing slashes for better compatibility
trailingSlash: true,
// Enable strict mode for better error catching
reactStrictMode: true,
// Enable experimental features for better performance
experimental: {
// Optimize CSS
optimizeCss: true,
// Enable optimized package imports for heavy libraries
optimizePackageImports: [
'framer-motion',
'@hookform/resolvers',
'react-markdown',
'remark-gfm',
'rehype-raw',
'rehype-sanitize',
'zod',
'zustand',
'lucide-react',
'@headlessui/react',
],
},
// Compiler options for better performance
compiler: {
// Remove console.log in production
removeConsole: isProductionBuild ? { exclude: ['error', 'warn'] } : false,
// Enable React compiler optimizations
reactRemoveProperties: isProductionBuild,
},
// Optimize transpilation
transpilePackages: ['react-markdown', 'remark-gfm', 'rehype-raw', 'rehype-sanitize'],
// Turbopack configuration (replaces webpack config)
turbopack: {
// Enable faster module resolution
resolveAlias: {
// Optimize common imports
'@': './src',
},
},
// Webpack optimizations for development (only when not using Turbopack)
webpack: (config, { dev, isServer }) => {
if (dev && !isServer && !process.env.TURBOPACK) {
// Optimize development builds
config.optimization = {
...config.optimization,
splitChunks: {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 10,
},
markdown: {
test: /[\\/]node_modules[\\/](react-markdown|remark-|rehype-)/,
name: 'markdown',
chunks: 'all',
priority: 20,
},
},
},
};
// Enable faster rebuilds
config.cache = {
type: 'filesystem',
buildDependencies: {
config: [__filename],
},
};
}
return config;
},
};
};
export default nextConfig;