refactor(build): extract shared build helpers into build-shared.js
Summary
This PR refactors the build system by extracting duplicated logic from dev.js and Rollup’s build-shared.js into a new shared helper module scripts/build-shared.js.
What this PR does
- Creates a new shared module
scripts/build-shared.jsthat exports:resolveDefinesresolveExternalresolveEntryFileresolveOutputFormatresolvePostfix
- Updates
dev.jsto use the new shared helper functions. - Removes duplicated logic across the build system.
- Ensures consistent behavior between development (esbuild) and production (Rollup).
Benefits
- Eliminates duplicated code between dev and prod build scripts.
- Creates a single source of truth for build-related utilities.
- Makes the build system easier to maintain and reason about.
I ran tests and simple benchmarks on my machine and observed no noticeable performance difference compared to the current implementation.
Summary by CodeRabbit
Release Notes
- Refactor
- Reorganized and consolidated internal build utilities into a centralized, reusable module to reduce code duplication across build configuration and development scripts. Build logic has been standardized for improved system maintainability. These infrastructure-level changes do not affect generated artifacts, features, or end-user functionality.
✏️ Tip: You can customize this high-level summary in your review settings.
Walkthrough
The pull request consolidates duplicated build configuration logic from rollup.config.js and scripts/dev.js into a new shared module (scripts/build-shared.js). Seven utility functions handle external module resolution, defines generation, entry file selection, output format mapping, and CJS ignore lists. Both build configs now import and use these shared utilities instead of maintaining inline implementations.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
Build shared utilities module scripts/build-shared.js |
New file introducing 7 exported utility functions: resolveExternal, getConsolidateDeps, resolveCJSIgnores, resolveDefines, resolveOutputFormat, resolvePostfix, and resolveEntryFile. Consolidates reusable build configuration logic with support for multiple formats, targets, and build modes. |
Rollup build configuration rollup.config.js |
Imports and replaces inline logic with shared utilities: resolveEntryFile for entry resolution, resolveDefines for compile-time defines, resolveExternalShared for external modules, and resolveCJSIgnores for CommonJS ignores. Removes redundant per-format branching. |
Dev build configuration scripts/dev.js |
Imports and replaces inline logic with shared utilities: resolveOutputFormat for output format mapping, resolvePostfix for runtime postfix adjustment, resolveExternal for external modules, and resolveDefines for compile-time defines. Reduces in-file conditional logic. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
- Straightforward refactoring following consistent pattern across files
- New utility functions are individual, testable pieces with moderate conditional logic
- Primary concern: verify that all edge cases and environment-specific behavior from original inline implementations are correctly preserved in shared functions
- Check parameter passing consistency between calling sites and utility signatures
Poem
🐰 Build logic scattered here and there, Now consolidated with care! Shared utilities, clean and bright— Duplication done, configs unite. ✨ One source of truth, no more despair!
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 75.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 |
|---|---|---|
| Title check | ✅ Passed | The title accurately describes the main refactoring: extracting shared build helpers into a new build-shared.js module. It's concise, specific, and clearly communicates the primary intent of the changeset. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] 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.
Deploy Preview for vue-sfc-playground failed. Why did it fail? →
| Name | Link |
|---|---|
| Latest commit | cb52fdbfef04dd65397b0b80eb4e37dc16688d56 |
| Latest deploy log | https://app.netlify.com/projects/vue-sfc-playground/deploys/6929d946f7eb3500085e0d63 |