Skip to content

Map elements to source

In development, feega-source-map adds data-feega-src="path/to/file.tsx:line:col" to every HTML element your code writes. Feega reads it from a live frame and knows which file and line to change. Production builds are left untouched.

Run in your project folder:

Terminal window
npx feega init --dry-run # show the changes
npx feega init # show them, ask, apply

init detects Vite or Next.js, adds the plugin to vite.config.* or wraps next.config.* with withFeegaSource, and adds feega-source-map to devDependencies. Running it again changes nothing. -y applies without asking.

Then install dependencies (npm install, pnpm install, …) and restart the dev server. The package is feega-source-map on npm.

By hand, Vite:

import { feegaSource } from 'feega-source-map/vite';
export default defineConfig({ plugins: [feegaSource(), react()] });

Next.js:

import { withFeegaSource } from 'feega-source-map/next';
export default withFeegaSource(nextConfig);
FrameworkFilesHow
Vite + React.jsx, .tsxVite plugin, dev server only
Vite + Svelte 5.svelteVite plugin, dev server only
Next.js 15 (webpack).jsx, .tsx, server and client componentswebpack loader, next dev only

Only host elements (div, button, …) are tagged. Components, fragments and member tags like motion.div are not: their elements carry the line inside the component.

The plugin also loads a small bridge in the page. The parent window (the Feega canvas, around a live frame iframe) sends:

iframe.contentWindow.postMessage({ type: 'feega:inspect', id: 1, x: 120, y: 40 }, '*');
// or { type: 'feega:inspect', id: 1, selector: '#cta' }

and receives { type: 'feega:inspect:result', id: 1, result }, where result holds source ({ file, line, col }), design-relevant computed styles, the element’s html (truncated), its rect, classes, text (when it has no child elements), the page’s root font size rem, and component: the nearest ancestor written in another file. The bridge announces itself with { type: 'feega:source-map:ready' }.

{ type: 'feega:preview', source: 'src/App.tsx:12:5', text, style } shows a change on every element written at that position before the file is saved; the next hot reload replaces it.

With Vite the bridge loads with Vite’s own client module, so it also runs in frameworks without an index.html, such as SvelteKit.

  • Next.js with Turbopack (next dev --turbopack): not tagged yet; use the default webpack dev server.
  • Vue SFC templates and MDX: not tagged yet.
  • Elements created outside JSX or templates (document.createElement, innerHTML) climb to the nearest tagged ancestor.