A Vite/Babel plugin for injecting source location attributes into JSX elements during React development. Current stable version: 0.2.1. This package extracts and centralizes the pattern originally scattered across multiple Analytics MFE projects using @wix/babel-plugin-jsx-source-attrs. It adds data-source-location (intrinsic elements) and data-component-source-location (custom components) attributes, with support for disabling in production, deduplication of existing attributes, path normalization (query/hash removal, virtual module prefixes, OS path separators), and TypeScript types. Unlike ad-hoc Babel plugin configurations, this offers a unified Vite plugin interface with simple options (enabled, attributeName, componentAttributeName). Requires @babel/core >=7.20.0 as a peer dependency. Dev-only dependency for build time; production builds must include devDependencies during CI.
npm install vite-plugin-jsx-source-attrsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to install and configure the Vite plugin with @vitejs/plugin-react, enabling source attributes only in development.
Upgrade @babel/core to 7.20.0 or later
Ensure devDependencies are installed at build time; use npm install (not npm ci --omit=dev) or equivalent
Use vitePluginJsxSourceAttrs() in plugins array instead of adding to babel plugins
Remove @wix/babel-plugin-jsx-source-attrs from dependencies and Babel config, replace with this package
Ensure no prior attribute with matching name is set manually; the plugin only adds if absent
Use import syntax; do not use require()
Run `npm install -D vite-plugin-jsx-source-attrs` and ensure CI installs devDependencies
Upgrade @babel/core to >=7.20.0
Use `import { vitePluginJsxSourceAttrs } from 'vite-plugin-jsx-source-attrs'`Convert to ESM in package.json ("type": "module") or use dynamic import()