From 08fb0c447074a6120f9cd45713e09d4c469acc77 Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Sun, 23 Mar 2025 22:59:04 +0000 Subject: [PATCH] fuck me --- .env.production | 14 ++++++++ .npmrc | 11 ++++++ OPTIMIZED-BUILD.md | 72 ++++++++++++++++++++++++++++++++++++++ next.config.mjs | 2 -- scripts/build-optimized.sh | 1 + scripts/optimize-build.js | 64 +++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 .env.production create mode 100644 .npmrc create mode 100644 OPTIMIZED-BUILD.md create mode 100644 scripts/build-optimized.sh create mode 100755 scripts/optimize-build.js diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..c41ca8d --- /dev/null +++ b/.env.production @@ -0,0 +1,14 @@ +# Disable telemetry for faster builds +NEXT_TELEMETRY_DISABLED=1 + +# Optimize build process +NEXT_OPTIMIZATION_LEVEL=2 + +# Reduce log verbosity +NEXT_LOG_LEVEL=error + +# Disable source maps in production +GENERATE_SOURCEMAP=false + +# API configuration +SERVER_API_URL=https://internal-api.inboxi.ng/api diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..bbe4dc4 --- /dev/null +++ b/.npmrc @@ -0,0 +1,11 @@ +# Optimize Node.js memory usage during builds +node-options=--max-old-space-size=4096 +# Disable update notifications during builds +update-notifier=false +# Optimize npm dependency resolution +legacy-peer-deps=true +# Reduce output noise +loglevel=error +# Speed up builds +fund=false +audit=false \ No newline at end of file diff --git a/OPTIMIZED-BUILD.md b/OPTIMIZED-BUILD.md new file mode 100644 index 0000000..e3e69e3 --- /dev/null +++ b/OPTIMIZED-BUILD.md @@ -0,0 +1,72 @@ +# Optimized Builds for Slower CPUs + +This document provides instructions for building the project on slower CPUs or resource-constrained environments. + +## Quick Start + +Run the optimized build using: + +```bash +npm run build:optimized +``` + +## Optimization Features + +The following optimizations have been implemented to improve build performance: + +1. **Memory Limit Control**: Sets Node.js memory limit to prevent crashes on memory-constrained systems +2. **Build Cache Management**: Automatically cleans up caches to prevent bloat +3. **TypeScript/ESLint Skip**: Skips type checking and linting during production builds +4. **Code Splitting**: Implements React.lazy() for code splitting and lazy loading +5. **Source Map Disabling**: Disables source maps in production for faster builds + +## Manual Optimization Steps + +If you need to manually optimize the build process: + +### 1. Clean the caches +```bash +npm run clean +``` + +### 2. Set Node.js memory limit +```bash +export NODE_OPTIONS="--max-old-space-size=4096" +``` + +### 3. Skip non-essential checks +```bash +NEXT_SKIP_LINT=1 NEXT_SKIP_TS_CHECK=1 npm run build +``` + +### 4. Use SWC compiler with optimized settings +```bash +NEXT_TELEMETRY_DISABLED=1 npm run build:fast +``` + +## Configuration Files + +The following configuration files have been optimized: + +- **next.config.mjs**: Contains SWC optimizations and standalone output +- **.npmrc**: Configures Node.js memory limits and disables notifications +- **.env.production**: Sets environment variables for production builds + +## Troubleshooting + +### Out of Memory Errors + +If you encounter "JavaScript heap out of memory" errors, try: + +```bash +export NODE_OPTIONS="--max-old-space-size=2048" +npm run build:fast +``` + +### Slow Builds + +If builds are still slow: + +1. Try running with lower memory settings +2. Disable unnecessary parts of the app temporarily +3. Build incrementally using `next build --no-lint` \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index a32b99c..29ae3a9 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -26,9 +26,7 @@ const nextConfig = { }, // Build optimization settings for slower CPUs experimental: { - // Use SWC minification which is faster than Terser swcMinify: true, - // Cache build artifacts for faster rebuilds turbotrace: { logLevel: 'error' } diff --git a/scripts/build-optimized.sh b/scripts/build-optimized.sh new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/scripts/build-optimized.sh @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/optimize-build.js b/scripts/optimize-build.js new file mode 100755 index 0000000..30c06a2 --- /dev/null +++ b/scripts/optimize-build.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node + +/** + * This script helps optimize builds on slower CPUs by: + * 1. Cleaning the .next cache directory to prevent it from growing too large + * 2. Setting environment variables for optimized builds + * 3. Clearing node_modules/.cache to prevent stale cache issues + */ + +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +// Paths +const rootDir = path.resolve(__dirname, '..'); +const nextDir = path.join(rootDir, '.next'); +const cacheDir = path.join(rootDir, 'node_modules', '.cache'); + +console.log('๐Ÿงน Cleaning build artifacts for faster build...'); + +// Clear Next.js cache selectively +if (fs.existsSync(nextDir)) { + try { + // Only remove the cache directory, not the entire .next folder + const cachePath = path.join(nextDir, 'cache'); + if (fs.existsSync(cachePath)) { + console.log(' Cleaning .next/cache directory...'); + fs.rmSync(cachePath, { recursive: true, force: true }); + } + } catch (err) { + console.error(' โŒ Error cleaning .next directory:', err.message); + } +} + +// Clear node_modules/.cache +if (fs.existsSync(cacheDir)) { + try { + console.log(' Cleaning node_modules/.cache directory...'); + fs.rmSync(cacheDir, { recursive: true, force: true }); + } catch (err) { + console.error(' โŒ Error cleaning node_modules/.cache:', err.message); + } +} + +console.log('โœ… Cleanup complete!'); +console.log('๐Ÿš€ Starting optimized build process...'); + +// Build with optimized settings +try { + execSync('npm run build:fast', { + stdio: 'inherit', + env: { + ...process.env, + NODE_ENV: 'production', + NEXT_TELEMETRY_DISABLED: '1', + NEXT_SKIP_LINT: '1', + NEXT_SKIP_TS_CHECK: '1', + } + }); + console.log('โœ… Build completed successfully!'); +} catch (err) { + console.error('โŒ Build failed:', err.message); + process.exit(1); +} \ No newline at end of file