-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnext.config.ts
More file actions
92 lines (85 loc) · 2.49 KB
/
next.config.ts
File metadata and controls
92 lines (85 loc) · 2.49 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
import type { NextConfig } from 'next';
import { execSync } from 'child_process';
// Run project detection at build time
function detectProjectConfig() {
try {
// Run the detection script to generate config files
execSync('node scripts/detect-project.js', { stdio: 'inherit' });
} catch {
console.warn('Could not run detection script');
}
// Use environment variable if set (from .env.local or CI/CD)
// Treat empty string as undefined to allow auto-detection in forks
const envBasePath = process.env.NEXT_PUBLIC_BASE_PATH;
if (envBasePath !== undefined && envBasePath !== '') {
return envBasePath;
}
// Read the auto-detected configuration using require
try {
const fs = require('fs');
const path = require('path');
const configPath = path.join(
__dirname,
'src',
'config',
'project-detected.json'
);
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
return config.basePath || '';
} catch {
// Final fallback if detection completely fails
console.warn('Could not read detected config, using empty base path');
return '';
}
}
const basePath = detectProjectConfig();
const nextConfig: NextConfig = {
output: 'export',
basePath: basePath,
assetPrefix: basePath ? `${basePath}/` : '',
trailingSlash: true,
images: {
unoptimized: true,
},
cleanDistDir: true,
env: {
NEXT_PUBLIC_PAGESPEED_API_KEY: process.env.NEXT_PUBLIC_PAGESPEED_API_KEY,
},
webpack: (config, { isServer }) => {
// Optimize code splitting for better performance
if (!isServer) {
config.optimization = {
...config.optimization,
splitChunks: {
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
// Vendor chunks for node_modules
vendor: {
name: 'vendor',
test: /[\\/]node_modules[\\/]/,
priority: 10,
reuseExistingChunk: true,
},
// Common chunks used across multiple pages
common: {
name: 'common',
minChunks: 2,
priority: 5,
reuseExistingChunk: true,
},
// Heavy libraries in separate chunks
leaflet: {
test: /[\\/]node_modules[\\/](leaflet|react-leaflet)[\\/]/,
name: 'leaflet',
priority: 20,
},
},
},
};
}
return config;
},
};
export default nextConfig;