Skip to content

Commit 4211e11

Browse files
Docs: document BUILD_POOL_TIMEOUT; Refactor: extract production build helpers
- Add BUILD_POOL_TIMEOUT to Build Performance Options for thread-loader pool timeout tuning - Extract duplicated parallel/sequential production build logic into a helper Validated with prettier, eslint, and production build
1 parent 039de91 commit 4211e11

File tree

2 files changed

+19
-44
lines changed

2 files changed

+19
-44
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Always reference these instructions first and fall back to search or bash comman
2929
- Options: `0|false|none`, `gzip` (or `brotli` if explicitly desired)
3030
- Affects only `.cache/webpack` size/speed; does not change final artifacts
3131
- BUILD_WATCH_ONCE (dev): When set, `npm run dev` runs a single build and exits (useful for timing)
32+
- BUILD_POOL_TIMEOUT: Override thread-loader production pool timeout (ms)
33+
- Default: `2000`. Increase if workers recycle too aggressively on slow machines/CI
3234

3335
Performance defaults: esbuild handles JS/CSS minification; in development CSS is injected via style-loader;
3436
in production CSS is extracted via MiniCssExtractPlugin; thread-loader is enabled by default in both dev and prod.

build.mjs

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -511,59 +511,32 @@ async function finishOutput(outputDirSuffix, sourceBuildDir = outdir) {
511511

512512
async function build() {
513513
await deleteOldDir()
514+
function createWebpackBuildPromise(isWithoutKatex, isWithoutTiktoken, minimal, tmpDir, suffix) {
515+
return new Promise((resolve, reject) =>
516+
runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, tmpDir, async (err, stats) => {
517+
if (err || (stats && typeof stats.hasErrors === 'function' && stats.hasErrors())) {
518+
console.error(err || stats.toString())
519+
reject(err || new Error('webpack error'))
520+
return
521+
}
522+
await finishOutput(suffix, tmpDir)
523+
resolve()
524+
}),
525+
)
526+
}
514527
if (isProduction && !isAnalyzing) {
515528
const tmpFull = `${outdir}/.tmp-full`
516529
const tmpMin = `${outdir}/.tmp-min`
517530
if (parallelBuild) {
518531
await Promise.all([
519-
new Promise((resolve, reject) =>
520-
runWebpack(true, true, true, tmpMin, async (err, stats) => {
521-
if (err || stats.hasErrors()) {
522-
console.error(err || stats.toString())
523-
reject(err || new Error('webpack error'))
524-
return
525-
}
526-
await finishOutput('-without-katex-and-tiktoken', tmpMin)
527-
resolve()
528-
}),
529-
),
530-
new Promise((resolve, reject) =>
531-
runWebpack(false, false, false, tmpFull, async (err, stats) => {
532-
if (err || stats.hasErrors()) {
533-
console.error(err || stats.toString())
534-
reject(err || new Error('webpack error'))
535-
return
536-
}
537-
await finishOutput('', tmpFull)
538-
resolve()
539-
}),
540-
),
532+
createWebpackBuildPromise(true, true, true, tmpMin, '-without-katex-and-tiktoken'),
533+
createWebpackBuildPromise(false, false, false, tmpFull, ''),
541534
])
542535
await fs.rm(tmpFull, { recursive: true, force: true })
543536
await fs.rm(tmpMin, { recursive: true, force: true })
544537
} else {
545-
await new Promise((resolve, reject) =>
546-
runWebpack(true, true, true, tmpMin, async (err, stats) => {
547-
if (err || stats.hasErrors()) {
548-
console.error(err || stats.toString())
549-
reject(err || new Error('webpack error'))
550-
return
551-
}
552-
await finishOutput('-without-katex-and-tiktoken', tmpMin)
553-
resolve()
554-
}),
555-
)
556-
await new Promise((resolve, reject) =>
557-
runWebpack(false, false, false, tmpFull, async (err, stats) => {
558-
if (err || stats.hasErrors()) {
559-
console.error(err || stats.toString())
560-
reject(err || new Error('webpack error'))
561-
return
562-
}
563-
await finishOutput('', tmpFull)
564-
resolve()
565-
}),
566-
)
538+
await createWebpackBuildPromise(true, true, true, tmpMin, '-without-katex-and-tiktoken')
539+
await createWebpackBuildPromise(false, false, false, tmpFull, '')
567540
await fs.rm(tmpFull, { recursive: true, force: true })
568541
await fs.rm(tmpMin, { recursive: true, force: true })
569542
}

0 commit comments

Comments
 (0)