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

@ryanclark/swc-plugin-jsx-marker

v1.0.0

Published

SWC plugin for adding attributes to design system components

Downloads

11

Readme

swc-plugin-jsx-marker

A simple SWC plugin that adds a data-uic attribute to JSX elements from a specified library. When using a design system library like Chakra UI, this plugin can help you identify the components in the DOM for easier debugging and testing. This works similarly to how the Emotion SWC plugin adds the name of the component to the class name. This plugin was adapted from the Emotion SWC plugin.

Installation

npm install @ryanclark/swc-plugin-jsx-marker --save-dev
pnpm add @ryanclark/swc-plugin-jsx-marker -D

Usage

Add the plugin to your SWC configuration. Here's an example using Vite with the @vitejs/plugin-react-swc plugin:

import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vite';

const config = defineConfig(({mode}) => ({
  plugins: react({
    plugins: [
      [
        '@ryanclark/swc-plugin-jsx-marker',
        {
          libraryName: '@example/design-system', // defaults to '@chakra-ui/react' if not specified
          enabled: mode !== 'production', // defaults to true if not specified
          // attributeName: 'data-testid', // defaults to 'data-uic' if not specified
        },
      ],
    ],
  }),
}));

export { config as default };

This plugin should come first in the list of plugins to ensure it runs before other transformations. It only adds the data-uic attribute to the JSX elements, so it needs to run before any other plugins that might modify the JSX.

This will transform this:

import { chakra, Box, Button, HStack } from '@chakra-ui/react';

const Item = chakra(Box)({
  baseStyle: {
    padding: '8px',
    border: '1px solid black',
  },
});

const StyledItem = styled(Item, {
  baseStyle: {
    padding: '16px',
    border: '1px solid red',
  },
});

function Example() {
  return (
    <HStack>
      <Item>
        <Button>Click me</Button>
      </Item>
      <StyledItem>
        <Button>Click me</Button>
      </StyledItem>
    </HStack>
  )
}

into:

import { chakra, Box, Button, HStack } from '@chakra-ui/react';

const Item = chakra(Box, {
  baseStyle: {
    padding: '8px',
    border: '1px solid black',
  },
});

const StyledItem = styled(Item, {
  baseStyle: {
    padding: '16px',
    border: '1px solid red',
  },
});

function Example() {
  return (
    <HStack data-uic="Example-HStack">
      <Item data-uic="Example-Item-Box">
        <Button>Click me</Button>
      </Item>
      <StyledItem data-uic="Example-StyledItem-Item">
        <Button>Click me</Button>
      </StyledItem>
    </HStack>
  )
}

Configuration Options

The plugin accepts the following configuration options:

| Option | Type | Default | Description | |-------------------|-----------|----------------------|-----------------------------------------------------------| | libraryName | string | '@chakra-ui/react' | The name of the library whose components should be marked | | enabled | boolean | true | Whether the plugin is enabled | | attributeName | string | 'data-uic' | The attribute name to add to the JSX elements |