Skip to content

Commit 60677bc

Browse files
authored
Merge pull request #67604 from ikevin127/kevin127-devHeapFollowUp
[NoQA] `webpack-dev-server` GC Plugin & Script Follow-Up
2 parents 62084c0 + 1643d92 commit 60677bc

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

config/webpack/ForceGarbageCollectionPlugin.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ class ForceGarbageCollectionPlugin {
1515
compiler.hooks.done.tap(this.constructor.name, () => {
1616
this.compilationCount++;
1717

18-
// Log memory usage every compilation
1918
const memUsage = process.memoryUsage();
2019
const heapUsedMB = Math.round(memUsage.heapUsed / 1024 / 1024);
2120
const heapTotalMB = Math.round(memUsage.heapTotal / 1024 / 1024);
2221

2322
console.log(`📊 Compilation #${this.compilationCount} - Heap: ${heapUsedMB}MB/${heapTotalMB}MB`);
2423
if (this.compilationCount % 5 === 0) {
2524
console.log(`🗑️ Forcing garbage collection after ${this.compilationCount} compilations`);
26-
// @ts-expect-error - gc is a global function provided when Node.js is started with --expose-gc flag
27-
gc();
25+
gc?.();
2826

29-
// Log memory after garbage collection
3027
const memAfterGC = process.memoryUsage();
3128
const heapAfterMB = Math.round(memAfterGC.heapUsed / 1024 / 1024);
3229
console.log(`✅ Post-GC heap size: ${heapAfterMB}MB (freed ${heapUsedMB - heapAfterMB}MB)`);

scripts/start-dev-with-auto-restart.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
# This script monitors for heap out of memory errors and automatically restarts
55
# Usage: ./start-dev-with-auto-restart.sh [webpack-dev-server arguments]
66

7-
WDS_ARGS=("$@")
7+
WEBPACK_DEV_SERVER_ARGS=("$@")
8+
readonly RESTART_DELAY=1
89
MAX_RESTARTS=10
910
RESTART_COUNT=0
10-
RESTART_DELAY=1
1111

1212
echo "🚀 Starting webpack-dev-server with auto-restart (max restarts: $MAX_RESTARTS)"
1313

1414
run_wds () {
1515
# Check if platform is Desktop to determine open behavior
16-
if [[ "${WDS_ARGS[*]}" == *"--env platform=desktop"* ]]; then
16+
if [[ "${WEBPACK_DEV_SERVER_ARGS[*]}" == *"--env platform=desktop"* ]]; then
1717
# For Desktop, always use --no-open since app is handled by Electron
18-
node --expose-gc --max-old-space-size=1100 ./node_modules/.bin/webpack-dev-server --no-open "${WDS_ARGS[@]}" --config config/webpack/webpack.dev.ts
18+
node --expose-gc ./node_modules/.bin/webpack-dev-server --no-open "${WEBPACK_DEV_SERVER_ARGS[@]}" --config config/webpack/webpack.dev.ts
1919
else
2020
# For Web, use the provided open flag
21-
node --expose-gc ./node_modules/.bin/webpack-dev-server "$1" "${WDS_ARGS[@]}" --config config/webpack/webpack.dev.ts
21+
node --expose-gc ./node_modules/.bin/webpack-dev-server "$1" "${WEBPACK_DEV_SERVER_ARGS[@]}" --config config/webpack/webpack.dev.ts
2222
fi
2323
}
2424

25-
while [ $RESTART_COUNT -lt $MAX_RESTARTS ]; do
25+
while [[ $RESTART_COUNT -lt $MAX_RESTARTS ]]; do
2626
echo "📊 Attempt #$((RESTART_COUNT + 1)) - Starting webpack-dev-server..."
2727

2828
if [ $RESTART_COUNT -eq 0 ]; then

0 commit comments

Comments
 (0)