-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdev-minimal.js
More file actions
76 lines (66 loc) · 2.3 KB
/
dev-minimal.js
File metadata and controls
76 lines (66 loc) · 2.3 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
/**
* Minimal development server for Next.js
* This script starts a minimal Next.js server with most features disabled
* for the fastest possible compilation and refresh times.
*/
const http = require('http');
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('🚀 Starting minimal development server...');
console.log('⚠️ Warning: Most features are disabled for faster compilation');
// Check if Next.js can be started
if (!fs.existsSync(path.join(__dirname, 'node_modules', 'next'))) {
console.error('Next.js not found in node_modules!');
process.exit(1);
}
// Clean up .next directory to prevent permission issues
try {
if (fs.existsSync(path.join(__dirname, '.next'))) {
console.log('Cleaning up .next directory...');
// This only removes trace files that might cause permission issues
const tracePath = path.join(__dirname, '.next', 'trace');
if (fs.existsSync(tracePath)) {
fs.rmSync(tracePath, { recursive: true, force: true });
}
}
} catch (error) {
console.warn('Failed to clean up .next directory:', error.message);
}
// Start the minimal Next.js dev server
process.env.NODE_ENV = 'development';
const nextProcess = spawn('node', ['node_modules/next/dist/bin/next', 'dev'], {
stdio: 'inherit',
env: {
...process.env,
// Disable all non-essential features
NEXT_DISABLE_SOURCEMAPS: 'true',
NEXT_TELEMETRY_DISABLED: '1',
NEXT_SKIP_TYPECHECKING: 'true',
NEXT_SKIP_LINTING: 'true',
NEXT_TRACE_PROFILING: 'false',
NEXT_DISABLE_WEBPACK_COMPILATION_TRACE: 'true',
// Disable any unnecessary optimizations
BROWSERSLIST_DISABLE_CACHE: 'true',
NEXT_DISABLE_IMAGE_OPTIMIZATION: 'true',
NODE_OPTIONS: '--max-old-space-size=4096',
},
});
// Handle errors and exits
nextProcess.on('error', (error) => {
console.error('Failed to start Next.js process:', error.message);
process.exit(1);
});
nextProcess.on('close', (code) => {
console.log(`Next.js process exited with code ${code}`);
process.exit(code);
});
// Handle termination signals
process.on('SIGINT', () => {
console.log('Stopping Next.js development server...');
nextProcess.kill('SIGINT');
});
process.on('SIGTERM', () => {
console.log('Stopping Next.js development server...');
nextProcess.kill('SIGTERM');
});