fix: exclude devtools code from production builds#5139
Conversation
Three changes to prevent Vue Devtools integration from leaking into
production bundles:
1. Wrap module-level variable initializations in __DEV__ guard so
they are eliminated as dead code in production builds.
2. Make refreshInspector a no-op in production by wrapping the
throttle() call in a __DEV__ ternary, removing the module-level
side effect that prevented tree-shaking.
3. Add /* @vite-ignore */ to the dynamic import('@vue/devtools-api')
to prevent Vite from creating a separate chunk for it in library
mode builds.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 30c2070 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for vee-validate-docs canceled.
|
✅ Deploy Preview for vee-validate-v5 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where Vue Devtools integration code was being retained in production/library builds, causing Vite to emit an extra devtools chunk when downstream projects build in library mode.
Changes:
- Moves devtools-related module-scope initializations behind
__DEV__so they can be dead-code-eliminated in production builds. - Makes
refreshInspectora production no-op to avoid a module-levelthrottle()side effect that blocked tree-shaking. - Adds
/* @vite-ignore */to the@vue/devtools-apidynamic import to prevent Vite from generating a separate chunk in library mode.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/vee-validate/src/devtools.ts | Gates devtools state initialization and inspector refresh logic behind __DEV__, and updates the dynamic import to avoid extra chunks in Vite library builds. |
| .changeset/fix-4972-devtools-production.md | Adds a patch changeset documenting the production build fix for #4972. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Fixes #4972
Vue Devtools integration code was being included in production builds, causing Vite to emit an extra
dist/index-[hash].jschunk file when building libraries that depend on vee-validate.Three changes address this:
__DEV__guard so they are eliminated as dead code in production builds, removing initialization side effects that prevented tree-shakingrefreshInspectora no-op in production by wrapping thethrottle()call in a__DEV__ternary, removing the module-level side effect that prevented the devtools module from being tree-shaken/* @vite-ignore */to the dynamicimport('@vue/devtools-api')to prevent Vite from creating a separate chunk for it in library mode buildsTest plan
refreshInspectoris properly conditioned onprocess.env.NODE_ENV !== 'production'/* @vite-ignore */annotation survives in the built.mjsoutput🤖 Generated with Claude Code