Skip to content

fix: exclude devtools code from production builds#5139

Open
logaretm wants to merge 1 commit intomainfrom
fix/4972-devtools-production
Open

fix: exclude devtools code from production builds#5139
logaretm wants to merge 1 commit intomainfrom
fix/4972-devtools-production

Conversation

@logaretm
Copy link
Owner

@logaretm logaretm commented Mar 4, 2026

Summary

Fixes #4972

Vue Devtools integration code was being included in production builds, causing Vite to emit an extra dist/index-[hash].js chunk file when building libraries that depend on vee-validate.

Three changes address this:

  • Wrap module-level variable initializations in __DEV__ guard so they are eliminated as dead code in production builds, removing initialization side effects that prevented tree-shaking
  • Make refreshInspector a no-op in production by wrapping the throttle() call in a __DEV__ ternary, removing the module-level side effect that prevented the devtools module from being tree-shaken
  • Add /* @vite-ignore */ to the dynamic import('@vue/devtools-api') to prevent Vite from creating a separate chunk for it in library mode builds

Test plan

  • All existing tests pass (63 test files, 386 tests)
  • Build output verified: IIFE and CJS builds contain zero devtools code
  • ESM build verified: refreshInspector is properly conditioned on process.env.NODE_ENV !== 'production'
  • ESM build verified: /* @vite-ignore */ annotation survives in the built .mjs output
  • Build sizes remain consistent (no unexpected increases)

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings March 4, 2026 06:48
@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2026

🦋 Changeset detected

Latest 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

@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for vee-validate-docs canceled.

Name Link
🔨 Latest commit 30c2070
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-docs/deploys/69a7d5d32113070008aab3e1

@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for vee-validate-v5 ready!

Name Link
🔨 Latest commit 30c2070
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-v5/deploys/69a7d5d39852000008653d97
😎 Deploy Preview https://deploy-preview-5139--vee-validate-v5.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 refreshInspector a production no-op to avoid a module-level throttle() side effect that blocked tree-shaking.
  • Adds /* @vite-ignore */ to the @vue/devtools-api dynamic 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vue Devtools Loaded Anyway In Production Build

2 participants