Vite Plugin Vue Tracer

1.3.0 · active · verified Sun Apr 19

vite-plugin-vue-tracer is a development-only Vite plugin designed to trace the source code location of elements and Virtual DOM nodes within Vue Single-File Components (SFCs). It serves as a modern replacement for `vite-plugin-vue-inspector`, leveraging Vite's internal source map capabilities to resolve source locations without injecting additional data attributes into the DOM. This approach aims for cleaner DOM and improved performance. The current stable version is `1.3.0`. The project maintains an active release cadence, frequently updating to support the latest versions of Vite and Vue DevTools. It differentiates itself by offering both a built-in overlay UI and headless APIs, allowing developers to build custom inspection tools or integrate tracing functionality more deeply into their development workflow.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `vite-plugin-vue-tracer` into a Vite project, enabling the built-in development overlay and listening for hover and click events to trace Vue component source locations. It shows both plugin configuration and client-side integration.

import { defineConfig } from 'vite'
import { VueTracer } from 'vite-plugin-vue-tracer'

export default defineConfig({
  plugins: [
    VueTracer(),
  ],
})

// In your main client-side entry file (e.g., main.ts)
// Only apply in development and if HMR is active
if (import.meta.hot) {
  import('vite-plugin-vue-tracer/client/overlay').then(({ events, state }) => {
    // Enable the visual overlay
    state.isEnabled = true

    events.on('hover', (info) => {
      console.log('Hovered:', info.filepath, info.line, info.column)
    })

    events.on('click', (info) => {
      console.log('Clicked:', info.filepath, info.line, info.column)
      // Example: Open in VS Code (requires custom setup for 'openInEditor')
      // openInEditor(`${info.filepath}:${info.line}:${info.column}`)
      state.isEnabled = false // Disable overlay after click for single use
    })
  })
}

view raw JSON →