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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@namnode/vite-plugin-inspect-react

v1.21.0

Published

A Vite plugin to inspect React components

Downloads

14

Readme

vite-plugin-inspect-react 💞

WHY 🙈

This plugin will inject special comment nodes next to your react components inside your codebase during compile time. Yet, those come with unique content that stores the location of your React components accordingly

This plugin is highly inspired by another fantastic plugin so-called vite-plugin-react-inspector. The reason this plugin exists because not all React's component libraries are built with extensibility in mind. To achieve certain consistency, they sacrifice the flexibility of the component's structure. For instance, some component libraries do not allow you to pass any props other than their pre-defined set of props. Therefore, dataset property injection is not an option anymore. This plugin helps to overcome that limitation 🎉

React's dev tool does have a feature to inspect the component's location, but it is not as accurate at scale in my experience. Therefore, I recommend you try out this plugin only when the React dev tool is not enough for your use case.

Demo

https://github.com/willnguyen1312/namnode/assets/17794897/6c48b24c-70b5-4ddb-a00f-3a1a5a27eff6

Installation 🚀

# pnpm
pnpm add @namnode/vite-plugin-inspect-react -D

# yarn
yarn add @namnode/vite-plugin-inspect-react -D

# npm
npm install @namnode/vite-plugin-inspect-react -D

# bun
bun install @namnode/vite-plugin-inspect-react -dev

Usage 🎉

// vite.config.ts
// Please ensure this plugin comes before react plugin, otherwise it can't detect your react component inside your source code.

import react from "@vitejs/plugin-react-swc"
import { defineConfig } from "vite"
import { inspectReact } from "@namnode/vite-plugin-inspect-react"

export default defineConfig({
  plugins: [inspectReact(), react()],
})
// Retrieve code path of component which render element in the DOM
import { getCodePathFromElement } from "@namnode/vite-plugin-inspect-react/utils"

const codePath = getCodePathFromElement(element)

Options 🎨

type Options = {
  predicate?: (node: Node) => boolean
  plugins?: PluginItem[]
  base?: string
  type?: "devtool" | "dom"
  propName?: string
}

function inspectReact(option?: Options): Plugin

predicate

By default, all nodes of type JSXElement will be inspected. However, you can pass a predicate function to filter out the nodes that you want to ignore.

plugins

Since the plugin is powered by @babel/core, you can pass any Babel plugins. For more information, please refer to Babel's documentation.

base

By default, the plugin will return the absolute path. However, you can override this behavior by passing a base, which will be used to resolve the relative path.

Development 🧑‍💻

Playground

From vite-plugin-inspect-react folder

pnpm dev

From root folder

pnpm start-inspect-react