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

@mockingjay-io/webpack-react-component-name

v1.0.2

Published

Makes React component names public on minified bundles

Downloads

608

Readme

Overview

webpack-react-component-name is a Webpack plugin that makes your custom React components visible within React Dev Tools and other tools that rely on the displayName parameter.

Note: This branch contains the version of this plugin that is compatible with Webpack 5. For support for Webpack 4, see 0.x branch/version of this plugin

Normally React component names are minified during compilation. This plugin makes these component names available in production bundles by hooking into Webpack's compilation process, traversing the AST looking for React component definitions, and updating the emitted source code to populate the displayName property. This is the property that, when populated, is used by the React Dev Tools extension to determine the name of a component.

Since we emit a displayName property value for each React component definition (critically, not every React component instance), using this plugin will result in a small size increase to your production bundles.

Installation

  1. Install via your prefered package manager:
npm install @mockingjay-io/webpack-react-component-name --save-dev
  1. Import and add the plugin to your Webpack configuration:
plugins: [
  new WebpackReactComponentNamePlugin({
    parseDependencies: true,
  })
],

Next.js users have to add this within next.config.js/next.config.mjs/next.config.ts. Examples available here.

Options

{
  "parseDependencies": false,
  "include": [],
  "exclude": []
}

parseDependencies

Type: boolean Default: false

If set true, the plugin will name the components exported from node_modules.

include

Type: (string | RegExp | (path: string) => boolean)[] Default: []

If the path matches any of the elements in this array, it will be included if it isn't explicitly excluded.

If the item is a string, it will use standard glob syntax. If the item is a Regular Expression, the path will be tested against it. If the item is a function, the path will be passed into it for testing.

exclude

Type: (string | RegExp | (path: string) => boolean)[] Default: []

If the path matches any of the elements in this array, it will be excluded.

If the item is a string, it will use standard glob syntax. If the item is a Regular Expression, the path will be tested against it. If the item is a function, the path will be passed into it for testing.

A truthy result will be excluded.

Troubleshooting

As you probably know, there is more than one way to define a React component. This plugin attempts to detect every possible way of defining a component, but there may be some we've missed. See the /examples directory and the unit tests for examples of the different permutations of React component definitions that we currently support.

If we are not detecting one of your components, please either file an Issue containing example source for a component which is not detected, or feel free to open a PR with the fix.

Note for Next.js users

In Next.js the plugin may cause warnings like [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item to be generated. These warnings are safe to ignore without any further action. But if you'd like to supress these warnings, as an interim solution, the following snippet can be added to your webpack config.

const webpackComponentNamesAppenderCacheWarning =
  /Skipped not serializable cache item.*ModuleAppenderDependency/i;

config.infrastructureLogging = {
  stream: {
    write: (message) => {
      if (webpackComponentNamesAppenderCacheWarning.test(message)) {
        return;
      }
      process.stderr.write(message);
    },
  },
};

License

This project is licensed under the terms of the MIT license. See LICENSE.md for more info.