|  | 
| 1 | 1 | import type { NextConfig } from 'next'; | 
|  | 2 | +import { PHASE_PRODUCTION_BUILD } from 'next/constants'; | 
| 2 | 3 | 
 | 
| 3 |  | -const nextConfig: NextConfig = { | 
| 4 |  | -  // Output as static site for GitHub Pages | 
| 5 |  | -  output: 'export', | 
| 6 |  | - | 
| 7 |  | -  // Base path for GitHub Pages (only in production AND not for Surge previews) | 
| 8 |  | -  basePath: | 
| 9 |  | -    process.env.NODE_ENV === 'production' && !process.env.SURGE_PREVIEW | 
| 10 |  | -      ? '/github-profile-readme-generator' | 
| 11 |  | -      : '', | 
| 12 |  | - | 
| 13 |  | -  // Image optimization for static export | 
| 14 |  | -  images: { | 
| 15 |  | -    unoptimized: true, // Required for static export | 
| 16 |  | -  }, | 
| 17 |  | - | 
| 18 |  | -  // Trailing slashes for better compatibility | 
| 19 |  | -  trailingSlash: true, | 
| 20 |  | - | 
| 21 |  | -  // Enable strict mode for better error catching | 
| 22 |  | -  reactStrictMode: true, | 
| 23 |  | - | 
| 24 |  | -  // Enable experimental features for better performance | 
| 25 |  | -  experimental: { | 
| 26 |  | -    // Optimize CSS | 
| 27 |  | -    optimizeCss: true, | 
| 28 |  | -    // Enable optimized package imports for heavy libraries | 
| 29 |  | -    optimizePackageImports: [ | 
| 30 |  | -      'framer-motion', | 
| 31 |  | -      '@hookform/resolvers', | 
| 32 |  | -      'react-markdown', | 
| 33 |  | -      'remark-gfm', | 
| 34 |  | -      'rehype-raw', | 
| 35 |  | -      'rehype-sanitize', | 
| 36 |  | -      'zod', | 
| 37 |  | -      'zustand', | 
| 38 |  | -      'lucide-react', | 
| 39 |  | -      '@headlessui/react', | 
| 40 |  | -    ], | 
| 41 |  | -  }, | 
| 42 |  | - | 
| 43 |  | -  // Compiler options for better performance | 
| 44 |  | -  compiler: { | 
| 45 |  | -    // Remove console.log in production | 
| 46 |  | -    removeConsole: process.env.NODE_ENV === 'production' ? { exclude: ['error', 'warn'] } : false, | 
| 47 |  | -    // Enable React compiler optimizations | 
| 48 |  | -    reactRemoveProperties: process.env.NODE_ENV === 'production', | 
| 49 |  | -  }, | 
| 50 |  | - | 
| 51 |  | -  // Optimize transpilation | 
| 52 |  | -  transpilePackages: ['react-markdown', 'remark-gfm', 'rehype-raw', 'rehype-sanitize'], | 
| 53 |  | - | 
| 54 |  | -  // Turbopack configuration (replaces webpack config) | 
| 55 |  | -  turbopack: { | 
| 56 |  | -    // Enable faster module resolution | 
| 57 |  | -    resolveAlias: { | 
| 58 |  | -      // Optimize common imports | 
| 59 |  | -      '@': './src', | 
|  | 4 | +const nextConfig = (phase: string): NextConfig => { | 
|  | 5 | +  // Determine if we should use basePath (production build, not Surge preview) | 
|  | 6 | +  const isProductionBuild = phase === PHASE_PRODUCTION_BUILD; | 
|  | 7 | +  const isSurgePreview = process.env.SURGE_PREVIEW === 'true'; | 
|  | 8 | +  const shouldUseBasePath = isProductionBuild && !isSurgePreview; | 
|  | 9 | +  const basePath = shouldUseBasePath ? '/github-profile-readme-generator' : ''; | 
|  | 10 | + | 
|  | 11 | +  return { | 
|  | 12 | +    // Output as static site for GitHub Pages | 
|  | 13 | +    output: 'export', | 
|  | 14 | + | 
|  | 15 | +    // Base path for GitHub Pages (only for production builds, not Surge previews) | 
|  | 16 | +    basePath, | 
|  | 17 | + | 
|  | 18 | +    // Asset prefix to ensure all assets use the correct path | 
|  | 19 | +    assetPrefix: shouldUseBasePath ? '/github-profile-readme-generator/' : '', | 
|  | 20 | + | 
|  | 21 | +    // Environment variables | 
|  | 22 | +    env: { | 
|  | 23 | +      NEXT_PUBLIC_BASE_PATH: basePath, | 
| 60 | 24 |     }, | 
| 61 |  | -  }, | 
| 62 |  | - | 
| 63 |  | -  // Webpack optimizations for development (only when not using Turbopack) | 
| 64 |  | -  webpack: (config, { dev, isServer }) => { | 
| 65 |  | -    if (dev && !isServer && !process.env.TURBOPACK) { | 
| 66 |  | -      // Optimize development builds | 
| 67 |  | -      config.optimization = { | 
| 68 |  | -        ...config.optimization, | 
| 69 |  | -        splitChunks: { | 
| 70 |  | -          chunks: 'all', | 
| 71 |  | -          cacheGroups: { | 
| 72 |  | -            vendor: { | 
| 73 |  | -              test: /[\\/]node_modules[\\/]/, | 
| 74 |  | -              name: 'vendors', | 
| 75 |  | -              chunks: 'all', | 
| 76 |  | -              priority: 10, | 
| 77 |  | -            }, | 
| 78 |  | -            markdown: { | 
| 79 |  | -              test: /[\\/]node_modules[\\/](react-markdown|remark-|rehype-)/, | 
| 80 |  | -              name: 'markdown', | 
| 81 |  | -              chunks: 'all', | 
| 82 |  | -              priority: 20, | 
|  | 25 | + | 
|  | 26 | +    // Image optimization for static export | 
|  | 27 | +    images: { | 
|  | 28 | +      unoptimized: true, // Required for static export | 
|  | 29 | +    }, | 
|  | 30 | + | 
|  | 31 | +    // Trailing slashes for better compatibility | 
|  | 32 | +    trailingSlash: true, | 
|  | 33 | + | 
|  | 34 | +    // Enable strict mode for better error catching | 
|  | 35 | +    reactStrictMode: true, | 
|  | 36 | + | 
|  | 37 | +    // Enable experimental features for better performance | 
|  | 38 | +    experimental: { | 
|  | 39 | +      // Optimize CSS | 
|  | 40 | +      optimizeCss: true, | 
|  | 41 | +      // Enable optimized package imports for heavy libraries | 
|  | 42 | +      optimizePackageImports: [ | 
|  | 43 | +        'framer-motion', | 
|  | 44 | +        '@hookform/resolvers', | 
|  | 45 | +        'react-markdown', | 
|  | 46 | +        'remark-gfm', | 
|  | 47 | +        'rehype-raw', | 
|  | 48 | +        'rehype-sanitize', | 
|  | 49 | +        'zod', | 
|  | 50 | +        'zustand', | 
|  | 51 | +        'lucide-react', | 
|  | 52 | +        '@headlessui/react', | 
|  | 53 | +      ], | 
|  | 54 | +    }, | 
|  | 55 | + | 
|  | 56 | +    // Compiler options for better performance | 
|  | 57 | +    compiler: { | 
|  | 58 | +      // Remove console.log in production | 
|  | 59 | +      removeConsole: isProductionBuild ? { exclude: ['error', 'warn'] } : false, | 
|  | 60 | +      // Enable React compiler optimizations | 
|  | 61 | +      reactRemoveProperties: isProductionBuild, | 
|  | 62 | +    }, | 
|  | 63 | + | 
|  | 64 | +    // Optimize transpilation | 
|  | 65 | +    transpilePackages: ['react-markdown', 'remark-gfm', 'rehype-raw', 'rehype-sanitize'], | 
|  | 66 | + | 
|  | 67 | +    // Turbopack configuration (replaces webpack config) | 
|  | 68 | +    turbopack: { | 
|  | 69 | +      // Enable faster module resolution | 
|  | 70 | +      resolveAlias: { | 
|  | 71 | +        // Optimize common imports | 
|  | 72 | +        '@': './src', | 
|  | 73 | +      }, | 
|  | 74 | +    }, | 
|  | 75 | + | 
|  | 76 | +    // Webpack optimizations for development (only when not using Turbopack) | 
|  | 77 | +    webpack: (config, { dev, isServer }) => { | 
|  | 78 | +      if (dev && !isServer && !process.env.TURBOPACK) { | 
|  | 79 | +        // Optimize development builds | 
|  | 80 | +        config.optimization = { | 
|  | 81 | +          ...config.optimization, | 
|  | 82 | +          splitChunks: { | 
|  | 83 | +            chunks: 'all', | 
|  | 84 | +            cacheGroups: { | 
|  | 85 | +              vendor: { | 
|  | 86 | +                test: /[\\/]node_modules[\\/]/, | 
|  | 87 | +                name: 'vendors', | 
|  | 88 | +                chunks: 'all', | 
|  | 89 | +                priority: 10, | 
|  | 90 | +              }, | 
|  | 91 | +              markdown: { | 
|  | 92 | +                test: /[\\/]node_modules[\\/](react-markdown|remark-|rehype-)/, | 
|  | 93 | +                name: 'markdown', | 
|  | 94 | +                chunks: 'all', | 
|  | 95 | +                priority: 20, | 
|  | 96 | +              }, | 
| 83 | 97 |             }, | 
| 84 | 98 |           }, | 
| 85 |  | -        }, | 
| 86 |  | -      }; | 
| 87 |  | - | 
| 88 |  | -      // Enable faster rebuilds | 
| 89 |  | -      config.cache = { | 
| 90 |  | -        type: 'filesystem', | 
| 91 |  | -        buildDependencies: { | 
| 92 |  | -          config: [__filename], | 
| 93 |  | -        }, | 
| 94 |  | -      }; | 
| 95 |  | -    } | 
| 96 |  | - | 
| 97 |  | -    return config; | 
| 98 |  | -  }, | 
|  | 99 | +        }; | 
|  | 100 | + | 
|  | 101 | +        // Enable faster rebuilds | 
|  | 102 | +        config.cache = { | 
|  | 103 | +          type: 'filesystem', | 
|  | 104 | +          buildDependencies: { | 
|  | 105 | +            config: [__filename], | 
|  | 106 | +          }, | 
|  | 107 | +        }; | 
|  | 108 | +      } | 
|  | 109 | + | 
|  | 110 | +      return config; | 
|  | 111 | +    }, | 
|  | 112 | +  }; | 
| 99 | 113 | }; | 
| 100 | 114 | 
 | 
| 101 | 115 | export default nextConfig; | 
0 commit comments