-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnext.config.js
More file actions
91 lines (87 loc) · 2.95 KB
/
Copy pathnext.config.js
File metadata and controls
91 lines (87 loc) · 2.95 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
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
// Overridable so CI/verification builds can run while `next dev` holds .next
distDir: process.env.NEXT_DIST_DIR || '.next',
env: {
NEWS_API_KEY: process.env.NEWS_API_KEY,
},
// `npm run dev:pro` / `build:pro` boot the app straight into the redesigned
// Pro workspace; the classic UI stays the default otherwise. The `ui=classic`
// escape hatch keeps the in-app Classic UI button working in pro mode —
// without it the redirect would bounce every visit to / straight back.
async redirects() {
if (process.env.NEXT_PUBLIC_UI_MODE === 'pro') {
return [
{
source: '/',
destination: '/pro',
permanent: false,
missing: [{ type: 'query', key: 'ui' }],
},
];
}
return [];
},
compiler: {
removeConsole: process.env.NODE_ENV === 'production' ? { exclude: ['error', 'warn'] } : false,
},
// Configure for transformers.js server-side usage and bundle optimization
webpack: (config, { isServer }) => {
if (isServer) {
// Externalize node-specific packages for server builds
config.externals = [...(config.externals || []), 'sharp', 'onnxruntime-node'];
}
// Optimize bundle splitting for large libraries
if (!isServer) {
config.optimization = {
...config.optimization,
moduleIds: 'deterministic',
splitChunks: {
chunks: 'all',
cacheGroups: {
// Split TensorFlow.js into its own chunk
tensorflow: {
test: /[\\/]node_modules[\\/]@tensorflow[\\/]tfjs[\\/]/,
name: 'tensorflow',
priority: 30,
reuseExistingChunk: true,
},
// Split WebGPU backend separately for better caching
tensorflowWebgpu: {
test: /[\\/]node_modules[\\/]@tensorflow[\\/]tfjs-backend-webgpu[\\/]/,
name: 'tensorflow-webgpu',
priority: 31,
reuseExistingChunk: true,
},
// Split transformers into its own chunk
transformers: {
test: /[\\/]node_modules[\\/]@xenova[\\/]/,
name: 'transformers',
priority: 30,
reuseExistingChunk: true,
},
// Split Recharts into its own chunk
recharts: {
test: /[\\/]node_modules[\\/]recharts[\\/]/,
name: 'recharts',
priority: 20,
reuseExistingChunk: true,
},
// Default vendors chunk
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: 10,
reuseExistingChunk: true,
},
},
},
};
}
return config;
},
}
module.exports = nextConfig
if (process.env.NODE_ENV === 'development') {
import('@opennextjs/cloudflare').then(m => m.initOpenNextCloudflareForDev());
}