Files
ember-market-frontend/next.config.mjs
g c31604d29a Enable dynamic rendering and update Next.js config
Added 'force-dynamic' export to admin orders and status pages for dynamic rendering. Updated next.config.mjs to modularize imports for better tree-shaking and switched to Turbopack for optimal bundle sizes. Upgraded Next.js and related dependencies in package.json and package-lock.json.
2025-12-31 07:05:26 +00:00

131 lines
3.6 KiB
JavaScript

import bundleAnalyzer from '@next/bundle-analyzer';
const withBundleAnalyzer = bundleAnalyzer({ enabled: process.env.ANALYZE === 'true' });
/** @type {import('next').NextConfig} */
const baseConfig = {
output: 'standalone',
reactStrictMode: false,
compress: process.env.NODE_ENV === 'production',
images: {
remotePatterns: [
{
protocol: "https",
hostname: "api.telegram.org",
},
{
protocol: "https",
hostname: "telegram.org",
},
...(process.env.API_HOSTNAME ? [{
protocol: "https",
hostname: process.env.API_HOSTNAME,
}] : []),
],
},
async rewrites() {
const apiBaseUrl = process.env.API_BASE_URL;
if (!apiBaseUrl || apiBaseUrl === 'undefined') {
console.warn('⚠️ API_BASE_URL not set! Set it to your backend domain');
console.warn('⚠️ Using localhost fallback - this will fail in production!');
return [
{
source: '/api/:path*',
destination: 'http://localhost:3001/api/:path*',
},
];
}
console.log(`🔗 API rewrites pointing to: ${apiBaseUrl}`);
return [
{
source: '/api/:path*',
destination: `${apiBaseUrl}/api/:path*`,
},
];
},
compiler: {
removeConsole: process.env.NODE_ENV === 'production' ? {
exclude: ['error', 'warn'],
} : false,
},
poweredByHeader: false,
// Modularize imports for better tree-shaking (only for libraries that benefit from it)
modularizeImports: {
// date-fns: function-level imports for better tree-shaking
'date-fns': {
transform: 'date-fns/{{member}}',
},
},
// Webpack config (fallback if using --webpack flag)
webpack: (config, { isServer, dev }) => {
if (!isServer && !dev) {
// Only apply aggressive code splitting in production
config.optimization = {
...config.optimization,
moduleIds: 'deterministic',
splitChunks: {
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
recharts: {
test: /[\\/]node_modules[\\/]recharts[\\/]/,
name: 'recharts',
chunks: 'all',
priority: 30,
},
radix: {
test: /[\\/]node_modules[\\/]@radix-ui[\\/]/,
name: 'radix-ui',
chunks: 'all',
priority: 25,
},
reactMarkdown: {
test: /[\\/]node_modules[\\/]react-markdown[\\/]/,
name: 'react-markdown',
chunks: 'all',
priority: 20,
},
dateFns: {
test: /[\\/]node_modules[\\/]date-fns[\\/]/,
name: 'date-fns',
chunks: 'all',
priority: 15,
},
framework: {
name: 'framework',
chunks: 'all',
test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
priority: 40,
enforce: true,
},
commons: {
name: 'commons',
minChunks: 2,
priority: 10,
},
},
},
};
}
return config;
},
onDemandEntries: {
maxInactiveAge: 15 * 1000,
pagesBufferLength: 2,
},
productionBrowserSourceMaps: false,
typescript: {
ignoreBuildErrors: true,
},
// Turbopack configuration for optimal bundle sizes
// Turbopack automatically handles code splitting and tree-shaking
turbopack: {},
};
const nextConfig = withBundleAnalyzer(baseConfig);
export default nextConfig;