A webpack loader that adds location metadata to JSX elements for development debugging. This loader automatically injects data-macaly-loc and data-macaly-name attributes into your JSX elements, making it easy to trace elements back to their source code location.
- 🎯 Precise location tracking: Shows exact file, line, and column for each JSX element
- 🚀 Zero runtime overhead: Only runs in development mode
- 🔧 Easy integration: Simple webpack configuration
- 📦 TypeScript support: Works with both
.jsxand.tsxfiles - 🚫 Smart filtering: Automatically excludes
node_modules, React Fragments, and non-DOM elements - 🎮 Custom renderer support: Compatible with React Three Fiber and other custom renderers via
ignorePackagesoption
npm install --save-dev macaly-taggerThe loader has the following dependencies that will be installed automatically:
@babel/parsermagic-stringestree-walker
Configure your next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
turbopack: {
rules: {
"*.{jsx,tsx}": {
condition: {
all: [
{ not: "foreign" }, // Exclude node_modules
"development", // Only in development mode
],
},
loaders: [
{
loader: "macaly-tagger",
options: {
disableSourceMaps: true, // Required to avoid Turbopack crashes
},
},
],
as: "*", // Preserve original file handling
},
},
},
};
module.exports = nextConfig;Important Notes for Turbopack:
disableSourceMaps: trueis required to prevent Turbopack crashes when processing source mapsas: "*"preserves the original file type handling (don't use"*.js")- Don't include
'browser'condition as it may exclude server components in Next.js- The simple
"*.{jsx,tsx}"glob pattern works correctly with these settings
Configure your next.config.js:
const path = require("path");
/** @type {import('next').NextConfig} */
const nextConfig = {
webpack: (config, { dev, isServer }) => {
// Only apply in development
if (dev) {
config.module.rules.unshift({
test: /\.(jsx|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: "macaly-tagger",
},
],
enforce: "pre", // Run before other loaders
});
}
return config;
},
};
module.exports = nextConfig;For custom webpack configurations:
module.exports = {
module: {
rules: [
{
test: /\.(jsx|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: "macaly-tagger",
},
],
enforce: "pre",
},
// ... other rules
],
},
};For Vite projects, you'll need a Vite plugin wrapper (not included in this package).
export default function TestComponent() {
return (
<div className="container">
<h1>Hello Macaly!</h1>
<button onClick={() => console.log("clicked")}>Click me</button>
<MyLib.SpecialButton />
</div>
);
}<div
data-macaly-loc="components/TestComponent.jsx:3:4"
data-macaly-name="div"
class="container"
>
<h1 data-macaly-loc="components/TestComponent.jsx:4:6" data-macaly-name="h1">
Hello Macaly!
</h1>
<button
data-macaly-loc="components/TestComponent.jsx:5:6"
data-macaly-name="button"
>
Click me
</button>
<button
data-macaly-loc="components/TestComponent.jsx:8:6"
data-macaly-name="MyLib.SpecialButton"
>
Special
</button>
</div>The loader:
- Parses JSX/TSX files using Babel parser
- Walks the AST to find JSX opening elements
- Adds location attributes with file path, line, and column information
- Preserves source maps for debugging
- Skips already tagged elements to avoid duplicates
The loader works out of the box with no configuration needed. It automatically:
- Processes only
.jsxand.tsxfiles - Excludes
node_modulesdirectory - Runs only in development mode (when configured properly)
- Handles both regular JSX elements (
<div>) and member expressions (<MyLib.Button>)
You can pass options to the loader:
{
loader: 'macaly-tagger',
options: {
debug: true, // Enable debug logging
disableSourceMaps: true, // Disable source map generation (useful for Turbopack)
ignorePackages: [ // Skip components imported from these packages
'@react-three/fiber',
'@react-three/drei',
],
},
}| Option | Type | Default | Description |
|---|---|---|---|
debug |
boolean |
false |
Enable detailed console logging for debugging |
disableSourceMaps |
boolean |
false |
Disable source map generation (recommended for Turbopack to avoid crashes) |
ignorePackages |
string[] |
[] |
List of package names whose imports should not be tagged |
If you're using custom React renderers like React Three Fiber, you may encounter errors because these renderers use components that don't support DOM attributes.
Use the ignorePackages option to skip tagging components imported from these packages:
{
loader: 'macaly-tagger',
options: {
ignorePackages: [
'@react-three/fiber',
'@react-three/drei',
'@react-three/postprocessing',
'three',
],
},
}This will automatically skip tagging any component imported from these packages:
import { Canvas } from '@react-three/fiber'; // Canvas will NOT be tagged
import { OrbitControls, Html } from '@react-three/drei'; // OrbitControls, Html will NOT be tagged
import * as Fiber from '@react-three/fiber'; // Fiber.* will NOT be tagged
function Scene() {
return (
<div> {/* ✓ Tagged (HTML element) */}
<Canvas> {/* ✗ Skipped (imported from @react-three/fiber) */}
<OrbitControls /> {/* ✗ Skipped (imported from @react-three/drei) */}
<Html> {/* ✗ Skipped (imported from @react-three/drei) */}
<span>Label</span> {/* ✓ Tagged (HTML element) */}
</Html>
<mesh> {/* ✗ Skipped (lowercase non-HTML element) */}
<boxGeometry /> {/* ✗ Skipped (lowercase non-HTML element) */}
</mesh>
</Canvas>
</div>
);
}The loader handles all import styles:
- Named imports:
import { Canvas } from '...' - Default imports:
import Drei from '...'(skipsDrei.Something) - Namespace imports:
import * as Fiber from '...'(skipsFiber.Something)
For each JSX element, the loader adds:
data-macaly-loc: File path, line, and column (e.g.,"components/Button.jsx:15:8")data-macaly-name: Component/element name (e.g.,"button"or"MyLib.Button")
Once installed, you can:
- Open browser DevTools
- Inspect any element
- See the
data-macaly-locattribute to find the exact source location - Use browser extensions or custom scripts to jump to source code
- Check console for errors: Look for
[macaly-tagger]warnings in the browser console - Verify development mode: Ensure the loader only runs in development (
dev && !isServerfor Next.js) - Check file extensions: Only
.jsxand.tsxfiles are processed
- Install dependencies: Ensure all peer dependencies are installed
- Check webpack version: Requires webpack >= 4.0.0 (for webpack setup)
- Verify loader path: Make sure the loader is correctly referenced
The loader is optimized for development:
- Only processes JSX/TSX files
- Excludes node_modules automatically
- Uses efficient AST walking
- Includes source map support
Add a console log to see which files are being processed:
// In your webpack config
{
loader: 'macaly-tagger',
options: {
debug: true // If you implement options support
}
}- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
- Added
ignorePackagesoption to skip tagging components imported from specified packages - Added automatic filtering for React Fragments (
<Fragment>,<React.Fragment>) - Added smart element filtering: only tags HTML/SVG elements and React components, skips unknown lowercase elements (custom renderer elements like R3F's
<mesh>,<boxGeometry>, etc.) - Improved compatibility with React Three Fiber and other custom renderers
- Added
disableSourceMapsoption to prevent Turbopack crashes - Added comprehensive Turbopack configuration documentation
- Tested and verified Turbopack compatibility with Next.js 15.3.0+
- Initial release
- Support for JSX and TSX files
- Location tracking with file, line, and column
- Member expression support (e.g.,
MyLib.Button) - Source map preservation