Refactor build pipeline for performance and dev output reliability
User description
Replace JS/CSS minifiers with esbuild to reduce build times while preserving outputs.
Enable thread-loader by default in dev and production. Choose workers dynamically (based on CPU cores) and allow overrides via environment variables. Keep filesystem cache enabled and make cache compression configurable, defaulting to uncompressed for faster warm builds on CPU-bound machines. Add BUILD_PARALLEL toggle (default on) to switch between parallel and sequential production variant builds. Ensure watch-once dev builds exit cleanly.
Adopt sass-embedded for SASS processing. In development, use style-loader to speed up CSS/SCSS compilation while keeping production outputs unchanged. Maintain CSP-safe source maps for extension contexts and suppress CSS 404 noise in development outputs.
Additionally, dependency caching has been added to the GitHub Actions workflow to accelerate CI/CD runs.
Results on this DO VPS (2 cores, ~4 GiB RAM):
- Production first run (cold): ~44s (baseline ~105s)
- Production second run (warm): ~19s (baseline ~39s)
- Development first run: ~31s; second run: ~29s
Times vary by environment; numbers above are for this machine.
Pull request summary from GitHub Copilot:
This pull request introduces several significant improvements to the build process, focusing on performance, configurability, and developer experience. The main changes include switching to faster build tools, adding advanced caching and parallelization options, updating build scripts, and improving CI build efficiency. These updates should result in faster builds, better resource utilization, and more flexibility for both local development and CI environments.
Build Performance and Tooling Improvements
- Switched JS minification from Terser to
esbuild(viaesbuild-loader) and enabled esbuild-based CSS minification for much faster production builds. (build.mjs,package.json) [1] [2]- Added support for parallel builds of production variants, controlled via the
BUILD_PARALLELenvironment variable, and enabled thread-loader for Babel by default (configurable viaBUILD_THREADandBUILD_THREAD_WORKERS). (build.mjs,.github/copilot-instructions.md) [1] [2] [3]- Introduced advanced Webpack cache options, allowing filesystem cache compression to be toggled with
BUILD_CACHE_COMPRESSIONfor improved warm build performance. (build.mjs,.github/copilot-instructions.md) [1] [2]Build Script and Output Enhancements
- Updated the build script to support both parallel and sequential builds, improved output directory management, and ensured correct copying of build artifacts for both production and development. (
build.mjs) [1] [2]- In development mode, the script now creates placeholder CSS files to prevent 404 errors in the browser. (
build.mjs) [1] [2]Continuous Integration (CI) Improvements
- Added npm and Webpack cache steps to the pre-release GitHub Actions workflow to speed up CI builds. (
.github/workflows/pre-release-build.yml)Dependency Updates
- Added new dependencies:
esbuild,esbuild-loader,sass-embedded,style-loader, andthread-loader; updatedsassandsass-loaderto latest versions; removedterser-webpack-pluginas it's no longer used. (package.json) [1] [2]Documentation
- Expanded the build instructions to document all new performance-related environment variables and their effects. (
.github/copilot-instructions.md)
PR Type
Enhancement
Description
-
Replace Terser/CSS minifiers with esbuild for faster builds
-
Enable thread-loader by default with configurable parallelism
-
Add filesystem cache compression control and parallel build options
-
Switch to sass-embedded and style-loader for dev builds
-
Add GitHub Actions dependency caching for CI acceleration
Diagram Walkthrough
flowchart LR
A["Old Build System"] --> B["esbuild Minification"]
A --> C["Thread-loader Parallelism"]
A --> D["Advanced Webpack Caching"]
A --> E["sass-embedded Processing"]
B --> F["Faster Production Builds"]
C --> F
D --> F
E --> F
G["GitHub Actions"] --> H["Dependency Caching"]
H --> I["Faster CI Builds"]
File Walkthrough
| Relevant files | |||||
|---|---|---|---|---|---|
| Enhancement |
| ||||
| Dependencies |
| ||||
| Documentation |
|
Summary by CodeRabbit
- Chores
- Improved pre-release CI: Node-major-aware cache keys and enabled npm + Webpack caching to speed up builds.
- Refactor
- Switched to esbuild-based JS/CSS minification and updated Sass/CSS loader pipeline.
- Added parallel, variant-aware builds with better caching, threading, and more robust build/finalization behavior.
- Documentation
- Added Build Performance Options documenting env vars for parallelism, threading, cache compression, watch-once, source maps, and output layout.
[!NOTE]
Other AI code review bot(s) detected
CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.
Walkthrough
The PR updates the pre-release CI workflow to add Node-aware npm and Webpack caching, overhauls build.mjs to introduce variant-aware, parallelizable builds with esbuild-based minification and threaded loaders, adjusts package.json dependencies accordingly, and expands AGENTS.md with build performance and output structure documentation.
Changes
| Cohort / File(s) | Summary |
|---|---|
CI workflow caching .github/workflows/pre-release-build.yml |
Adds Node major detection and exports NODE_MAJOR; enables npm cache via actions/setup-node; adds actions/cache for Webpack filesystem cache keyed by OS, NODE_MAJOR, and lockfile hash; restores/saves Webpack cache; build commands unchanged. |
Build system core overhaulbuild.mjs |
Introduces variant-aware, optionally parallel build orchestration; updates runWebpack and finishOutput signatures to accept sourceBuildDir; switches to esbuild-based JS/CSS minification; conditional thread-loader support and thread pool controls; dynamic sass-embedded import with fallback; per-variant filesystem caches and output dirs; improved error handling, streaming zipping, file copying, and dev CSS placeholders/source maps. |
Dependencies and toolingpackage.json |
Adds @babel/runtime; adds esbuild and esbuild-loader; upgrades/changes Sass tooling (sass, sass-embedded, sass-loader); adds style-loader and thread-loader; removes terser-webpack-plugin. |
Documentation updatesAGENTS.md |
Adds Build Performance Options documenting BUILD_PARALLEL, BUILD_THREAD, BUILD_THREAD_WORKERS, BUILD_CACHE_COMPRESSION, BUILD_WATCH_ONCE, BUILD_POOL_TIMEOUT; notes source map behavior, resolve.symlinks rationale, and detailed production output structure and variants. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor Dev as Developer / CI
participant Build as build.mjs
participant WP as Webpack Compiler
participant FS as Filesystem
participant Zip as Zipper
Dev->>Build: build()
activate Build
Build->>Build: derive variants + env (parallel, threads, cache)
alt Parallel enabled
par For each variant
Build->>WP: runWebpack(..., sourceBuildDir)
WP-->>FS: emit assets to per-variant dir
Build->>Build: finishOutput(suffix, sourceBuildDir)
Build->>Zip: zipFolder(...)
and For next variant
end
else Sequential
loop variants
Build->>WP: runWebpack(..., sourceBuildDir)
WP-->>FS: emit assets to per-variant dir
Build->>Build: finishOutput(suffix, sourceBuildDir)
Build->>Zip: zipFolder(...)
end
end
Build-->>Dev: exit 0 or error (non-zero)
deactivate Build
sequenceDiagram
autonumber
actor CI as GitHub Actions
participant Setup as actions/setup-node
participant CacheNpm as npm cache (setup-node)
participant CacheWP as actions/cache (Webpack)
participant Job as build job
CI->>Setup: setup-node with cache: npm
Setup->>CacheNpm: restore by OS + lockfile hash
CI->>Job: Detect NODE_MAJOR and export
CI->>CacheWP: restore .cache/webpack using OS + NODE_MAJOR + lockfile hash
CI->>Job: npm ci && npm run build
Job-->>CacheWP: save updated Webpack cache (post)
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- ChatGPTBox-dev/chatGPTBox#891 — Modifies
AGENTS.md; likely overlaps in documentation sections and contributor guidance.
Suggested labels
Review effort 2/5
Poem
I thump my paws—cache warms the trail,
Threads hum softly, builds set sail.
Esbuild breezes, Sass in tune,
Variants dance from noon to moon.
Zip! goes the bundle—swift and light. 🐇✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | The title succinctly and accurately reflects the primary change: a refactor of the build pipeline aimed at performance improvements (esbuild, caching, parallel/threaded builds) and improved developer output reliability (watch-once behavior, dev CSS placeholders, stable source maps). It is concise, specific, and clear enough for a teammate scanning PR history to understand the main intent. |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewPossible Issue
runWebpack signature adds sourceBuildDir before callback, but many internal calls pass parameters that may shift positions incorrectly if any call sites or future edits assume the old order. Validate all invocations use the new 5-arg form consistently and that sourceBuildDir is always a string when expected. |
PR Code Suggestions ✨
Latest suggestions up to 5663e3c
| Category | Suggestion | Impact |
| Possible issue |
Ensure production failures exit non-zeroIn production, if the callback throws or returns a rejected promise, the process
Suggestion importance[1-10]: 8__ Why: This is a critical bug fix for CI/CD, as it ensures that a failed production build correctly returns a non-zero exit code, preventing broken builds from being treated as successful. | Medium |
Fix boolean env parsingThis helper treats any non-empty string as true, so
Suggestion importance[1-10]: 5__ Why: The suggestion correctly identifies that | Low | |
| Incremental [*] |
Harden cache invalidation keysInclude
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies that the Webpack cache key should include versions of key build tools to prevent stale cache issues after dependency upgrades, which is a valuable improvement for cache robustness. | Medium |
Stabilize Sass builds and warningsPass
Suggestion importance[1-10]: 6__ Why: This suggestion correctly proposes using | Low | |
| General |
Validate worker count strictly
Suggestion importance[1-10]: 5__ Why: The suggestion correctly identifies a weakness in using | Low |
| ||
Previous suggestions
✅ Suggestions up to commit 6c89d29
| Category | Suggestion | Impact |
| General |
✅
| Medium |
| Incremental [*] |
Make symlink resolution configurableAdd a conditional to re-enable
Suggestion importance[1-10]: 6__ Why: The suggestion improves developer experience by adding a configurable flag for | Low |
| Possible issue |
✅
| Low |
✅ Suggestions up to commit abfc14d
| Category | Suggestion | Impact |
| Incremental [*] |
Use external source maps in devAlign devtool with external map files by switching to external source maps in
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies that | Medium |
| Possible issue |
✅
| Medium |
| General |
Reduce default thread oversubscriptionSpawning threads equal to total CPUs can oversubscribe when Webpack already
Suggestion importance[1-10]: 6__ Why: The suggestion correctly identifies a potential performance issue with thread oversubscription and proposes a reasonable heuristic ( | Low |
✅ Suggestions up to commit b5f27c3
| Category | Suggestion | Impact |
| General |
✅
| Medium |
| Possible issue |
Cap worker pool below CPU countCap worker count to at least 1 and at most CPU count minus one to avoid starving
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies a potential performance issue where using all CPU cores for workers can starve the main thread, and proposes a standard practice of reserving one core, which improves build stability. | Medium |
✅ Suggestions up to commit 0fdeae8
| Category | Suggestion | Impact |
| Incremental [*] |
Fix CI cache orderingMove the Webpack cache restore step before installing dependencies so that cache .github/workflows/pre-release-build.yml [24-46]
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies that using the built-in | Medium |
✅
| Low | |
| Possible issue |
✅
| Medium |
| General |
Leave one CPU core freeCap the default worker count to CPU count minus one to avoid exhausting all
Suggestion importance[1-10]: 6__ Why: The suggestion improves system stability by default by leaving one CPU core free for other tasks, which is a sensible performance optimization. | Low |
✅ Suggestions up to commit d9cc0eb
| Category | Suggestion | Impact |
| Incremental [*] |
Add Node version to cache keyEnsure the cache key incorporates the Node major version so caches don't get .github/workflows/pre-release-build.yml [27-35]
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies that the | Medium |
Prevent null stats accessGuard against a null stats object before calling hasErrors to prevent runtime
Suggestion importance[1-10]: 6__ Why: This is a valid defensive programming suggestion that prevents a potential runtime error by checking if the | Low | |
✅
| Low | |
| Possible issue |
Prevent unsafe thread-loader usageAvoid using
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies a potential stability issue with using | Medium |
✅ Suggestions up to commit 7bad746
| Category | Suggestion | Impact |
| Possible issue |
✅
| Medium |
✅
| Low | |
| General |
Add build config to cache keyThe cache key ignores webpack config changes, risking stale caches and wrong .github/workflows/pre-release-build.yml [37-45]
Suggestion importance[1-10]: 7__ Why: The suggestion correctly identifies that the Webpack cache key in the CI workflow is incomplete because it doesn't account for changes in | Medium |
| Incremental [*] |
✅
| Low |
| Possible issue |
✅
|
@codex review
@coderabbitai review
✅ Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
@codex review
@codex review
@codex review
@codex review @coderabbitai review
@PeterDaveHello I'll trigger a review of the build pipeline refactor changes in PR #886. This comprehensive update introduces esbuild-based optimization, thread-loader parallelization, and various performance enhancements.
✅ Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
@codex review
Codex Review: Didn't find any major issues. Keep them coming!
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
@codex review
@codex review
@codex review
Codex Review: Didn't find any major issues. Keep it up!
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
@codex review
Codex Review: Didn't find any major issues. Chef's kiss.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
@codex review
Codex Review: Didn't find any major issues. Chef's kiss.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
/gemini review
@codex review
/gemini review
Codex Review: Didn't find any major issues. Nice work!
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
/gemini review @codex review
Hello @PeterDaveHello, I noticed you've invoked /gemini review. As an AI assistant, I'm designed to provide detailed feedback and suggestions within comments on specific code changes or answer questions you might have about the pull request. I don't execute commands like /gemini review to initiate a full, new review cycle.
However, I've already reviewed this pull request, and I can offer further insights or address any specific questions you have regarding the build pipeline refactor, esbuild integration, threading, or caching improvements. Feel free to ask!
/gemini review @codex review
/gemini review
/gemini review