chore: exclude mockServiceWorker.js from production builds BED-7993#2651
chore: exclude mockServiceWorker.js from production builds BED-7993#2651elikmiller merged 3 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a Vite build-only plugin that, on closeBundle, resolves the build output path (from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/ui/vite.config.ts`:
- Around line 123-126: The cleanup hook currently reads process.env.BUILD_PATH
instead of the Vite-resolved output directory; update the plugin to capture
Vite's resolved build.outDir in configResolved (store it in a plugin-scoped
variable like resolvedOutDir) and then use that resolvedOutDir inside
closeBundle (instead of process.env.BUILD_PATH) to compute mockServiceWorkerPath
(e.g., path.resolve(__dirname, resolvedOutDir, 'mockServiceWorker.js')),
ensuring the file is removed from the actual build output directory configured
via loadEnv.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: ed185af1-c974-4437-83a3-f9be0ced933b
📒 Files selected for processing (1)
cmd/ui/vite.config.ts
utafrali
left a comment
There was a problem hiding this comment.
The custom Vite plugin is a clean, well-scoped solution and the closeBundle + apply: 'build' combination is the right approach. There is one real bug: the plugin resolves the output directory from process.env.BUILD_PATH while the build config uses Vite's loadEnv, so any BUILD_PATH set in a .env file would be invisible to the plugin, causing a silent no-op deletion.
zinic
left a comment
There was a problem hiding this comment.
Upon testing this drops the file on disk but when I run the service I can no longer request it from the API. This appears to be working as intended.
Description
Excludes
mockServiceWorker.jsfrom production builds while keeping it available for development mode.MSW (Mock Service Worker) requires the service worker file to be served from the public directory to function properly in development. However, this file should not be included in production builds as it's only needed for local mocking during development.
This PR adds a custom Vite plugin that automatically removes
mockServiceWorker.jsfrom the build output after Vite copies public assets to the dist folder.Motivation and Context
Resolves BED-7993
The mockServiceWorker.js file was being included in production builds, adding unnecessary development-only code to the production bundle. This change ensures that MSW artifacts are excluded from production while maintaining full functionality in development mode.
How Has This Been Tested?
yarn buildScreenshots (optional):
N/A
Types of changes
Checklist:
Summary by CodeRabbit