npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@builder.io/webpack-plugin-jsx-loc

v0.1.2

Published

Webpack plugin that adds location data to JSX elements

Readme

webpack-plugin-jsx-loc

A Webpack plugin that adds data-loc attributes to JSX elements, containing the file path and line number where the element is defined. This is useful for debugging, component tracking, and analytics.

Installation

npm install --save-dev webpack-plugin-jsx-loc
# or
yarn add --dev webpack-plugin-jsx-loc

Usage

Add the plugin to your Webpack configuration:

// webpack.config.js
const { JsxLocPlugin } = require('@builder.io/webpack-plugin-jsx-loc');

module.exports = {
  // ... other webpack config
  plugins: [
    new JsxLocPlugin({
      // Optional: specify custom include/exclude patterns
      // include: [/src\/components/],
      // exclude: [/node_modules/, /test/]
    })
  ]
};

Options

  • include: RegExp or array of RegExp patterns to include specific files (optional)
  • exclude: RegExp or array of RegExp patterns to exclude specific files (optional, defaults to /node_modules/)

How It Works

The plugin adds a data-loc attribute to JSX elements that contains the relative file path and line number:

// Input
<Button onClick={handleClick}>Click me</Button>

// Output
<Button data-loc="src/components/MyComponent.tsx:42" onClick={handleClick}>Click me</Button>

This allows you to identify where components are defined when inspecting the DOM.

Complex Component Support

The plugin handles a variety of JSX patterns:

  • Regular JSX elements with attributes
  • Member expressions (e.g., <Namespace.Component />)
  • Namespaced elements (e.g., <svg:path />)
  • JSX inside decorators and complex class components
  • Components with TypeScript interfaces and typing
  • CSS-in-JS libraries (emotion, styled-components)
  • Components with spread attributes

React Fragments are intentionally skipped and won't receive a data-loc attribute:

  • <React.Fragment> elements
  • Shorthand fragment syntax <>
  • <Fragment> elements

Testing the Plugin

This package includes comprehensive tests and manual testing scripts:

# Run the automated tests
npm test

# Run tests in watch mode
npm run test:watch

# Update snapshots if code changes intentionally 
npm test -- -u

# Test with a JSX file fixture
npm run test:jsx

# Test with a TSX file fixture
npm run test:tsx

Tests are powered by Vitest, a fast test runner built on top of Vite.

The test suite uses real fixtures to verify the plugin's behavior with a variety of components:

  • Simple components
  • Components with fragments
  • Complex components with decorators and nested JSX
  • Components using CSS-in-JS libraries
  • Components with TypeScript interfaces and typing
  • Real-world complex components with hundreds of lines of code and multiple levels of nesting

Both unit tests and integration tests ensure that the plugin correctly adds data-loc attributes even to highly complex components with nested structures, decorators, CSS-in-JS properties, and other challenging patterns.

Tests include both assertions and inline snapshots that precisely verify the transformation output to catch any regressions or unexpected changes in how JSX is processed.

The test scripts generate output in src/__tests__/output/ where you can inspect the transformation results.

Notes

  • Only works with .jsx and .tsx files
  • Skips React.Fragment and Fragment elements
  • Preserves source maps
  • Handles complex JSX patterns safely with error recovery
  • Supports modern JavaScript syntax including:
    • Class features (decorators, private properties, static blocks)
    • Modern JS features (dynamic imports, optional chaining, nullish coalescing)
    • TypeScript syntax
    • Top-level await, numeric separators, BigInt and other recent additions