fuck me
This commit is contained in:
14
.env.production
Normal file
14
.env.production
Normal file
@@ -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
|
||||
11
.npmrc
Normal file
11
.npmrc
Normal file
@@ -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
|
||||
72
OPTIMIZED-BUILD.md
Normal file
72
OPTIMIZED-BUILD.md
Normal file
@@ -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`
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
1
scripts/build-optimized.sh
Normal file
1
scripts/build-optimized.sh
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
64
scripts/optimize-build.js
Executable file
64
scripts/optimize-build.js
Executable file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user