{"id":32867315,"url":"https://github.com/mockingjay-io/react-display-name-plugin","last_synced_at":"2026-01-20T17:27:50.449Z","repository":{"id":322436332,"uuid":"1089454330","full_name":"mockingjay-io/react-display-name-plugin","owner":"mockingjay-io","description":"Build plugin that preserves React component names in production. Supports Webpack, Next.js \u0026 Vite.","archived":false,"fork":false,"pushed_at":"2025-11-04T12:29:37.000Z","size":895,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-04T14:15:00.851Z","etag":null,"topics":["devtools","react","vite","webpack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mockingjay-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-04T11:15:12.000Z","updated_at":"2025-11-04T12:29:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mockingjay-io/react-display-name-plugin","commit_stats":null,"previous_names":["mockingjay-io/react-display-name-plugin"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mockingjay-io/react-display-name-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingjay-io%2Freact-display-name-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingjay-io%2Freact-display-name-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingjay-io%2Freact-display-name-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingjay-io%2Freact-display-name-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mockingjay-io","download_url":"https://codeload.github.com/mockingjay-io/react-display-name-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mockingjay-io%2Freact-display-name-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283637490,"owners_count":26868920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-10T02:00:06.292Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devtools","react","vite","webpack"],"created_at":"2025-11-09T06:01:18.186Z","updated_at":"2025-11-11T08:01:52.280Z","avatar_url":"https://github.com/mockingjay-io.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build and Test](https://github.com/mockingjay-io/react-display-name-plugin/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/mockingjay-io/react-display-name-plugin/actions/workflows/build-and-test.yml)\n[![codecov](https://codecov.io/gh/mockingjay-io/react-display-name-plugin/graph/badge.svg?token=X8XYSPSGI4)](https://codecov.io/gh/mockingjay-io/react-display-name-plugin)\n[![NPM Version](https://img.shields.io/npm/v/react-display-name-plugin)](https://www.npmjs.com/package/react-display-name-plugin)\n\n# React displayName Plugin\n\n**react-display-name-plugin** is a build plugin for Webpack, Next.js \u0026 Vite that makes your custom\nReact components visible within React Dev Tools and other tools that rely on the displayName parameter.\n\n_Note: This package supports Webpack 5 and Vite 2+. For older versions (Webpack 4), see the legacy package [@mockingjay-io/webpack-react-component-name](https://github.com/mockingjay-io/webpack-react-component-name)._\n\nNormally React component names are minified during compilation. This plugin\nmakes these component names available in production bundles by hooking into\nyour build tool's compilation process, traversing the AST looking for React component\ndefinitions, and updating the emitted source code to populate the\n[displayName](https://reactjs.org/docs/react-component.html#displayname)\nproperty. This is the property that, when populated, is used by the React Dev\nTools extension to determine the name of a component.\n\nSince we emit a `displayName` property value for each React component definition\n(critically, **not** every React component _instance_), using this plugin will\nresult in a small size increase to your production bundles.\n\n## Installation\n\n1. Install via your preferred package manager:\n\n```bash\nnpm install react-display-name-plugin --save-dev\n```\n\n### For Webpack\n\n2. Import and add the plugin to your Webpack configuration:\n\n```js\nconst ReactDisplayNamePlugin = require('react-display-name-plugin/webpack');\n\nmodule.exports = {\n  // ... other config\n  plugins: [\n    new ReactDisplayNamePlugin({\n      parseDependencies: true,\n    })\n  ],\n};\n```\n\n### For Vite\n\n2. Import and add the plugin to your Vite configuration:\n\n```js\n// vite.config.js / vite.config.ts\nimport { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\nimport reactDisplayNamePlugin from 'react-display-name-plugin/vite';\n\nexport default defineConfig({\n  plugins: [\n    react(),\n    reactDisplayNamePlugin({\n      parseDependencies: true,\n    })\n  ],\n});\n```\n\n**Note:** The Vite plugin should be placed after the React plugin in your plugins array, as it needs to run after JSX transformation.\n\n### For Next.js\n\nNext.js uses Webpack under the hood, so you'll need to customize the Webpack configuration in your Next.js config file.\n\n\u003e **⚠️ Important:** This plugin currently only works with Webpack. If you're using Turbopack (Next.js's new bundler), you'll need to [opt back into using Webpack](https://nextjs.org/docs/app/api-reference/turbopack#using-webpack-instead).\n\n#### Using next.config.js (CommonJS)\n\n```js\nconst ReactDisplayNamePlugin = require('react-display-name-plugin/webpack');\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n  webpack: (config) =\u003e {\n    config.plugins.push(\n      new ReactDisplayNamePlugin({\n        parseDependencies: true,\n      })\n    );\n\n    return config;\n  },\n};\n\nmodule.exports = nextConfig;\n```\n\n#### Using next.config.mjs (ES Modules)\n\n```js\nimport ReactDisplayNamePlugin from 'react-display-name-plugin/webpack';\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n  webpack: (config) =\u003e {\n    config.plugins.push(\n      new ReactDisplayNamePlugin({\n        parseDependencies: true,\n      })\n    );\n\n    return config;\n  },\n};\n\nexport default nextConfig;\n```\n\n#### Suppressing Webpack Cache Warnings (Optional)\n\nNext.js may generate warnings like `[webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item`. These are safe to ignore, but if you want to suppress them:\n\n```js\nimport ReactDisplayNamePlugin from 'react-display-name-plugin/webpack';\n\nconst webpackComponentNamesAppenderCacheWarning =\n  /Skipped not serializable cache item.*ModuleAppenderDependency/i;\n\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n  webpack: (config) =\u003e {\n    config.plugins.push(\n      new ReactDisplayNamePlugin({\n        parseDependencies: true,\n      })\n    );\n\n    // Suppress cache warnings\n    config.infrastructureLogging = {\n      level: 'error',\n      stream: {\n        write: (message) =\u003e {\n          if (webpackComponentNamesAppenderCacheWarning.test(message)) {\n            return;\n          }\n          process.stderr.write(message);\n        },\n      },\n    };\n\n    return config;\n  },\n};\n\nexport default nextConfig;\n```\n\n**See working examples:** Check the [examples directory](https://github.com/mockingjay-io/react-display-name-plugin/tree/main/examples) for Next.js 12, 13, and 14 configurations with both App Router and Pages Router.\n\n### Core Utilities (Advanced)\n\nFor building custom plugins for other bundlers, you can import the core utilities directly:\n\n```js\nconst {\n  detectReactComponents,\n  generateDisplayNameCode\n} = require('react-display-name-plugin');\nconst { parse } = require('acorn');\n\nconst code = 'function MyComponent() { return \u003cdiv\u003eHello\u003c/div\u003e; }';\nconst ast = parse(code, { ecmaVersion: 'latest', sourceType: 'module' });\n\ndetectReactComponents(ast, (node) =\u003e {\n  const componentName = node.id.name;\n  const injectionCode = generateDisplayNameCode(componentName);\n  console.log(injectionCode); // ;try{MyComponent.displayName=\"MyComponent\";}catch(e){}\n});\n```\n\n**Available Utilities:**\n- `detectReactComponents(ast, callback)` - Walks an AST and detects React components\n- `generateDisplayNameCode(componentName)` - Generates displayName injection code\n- `argumentCreatesElement(argument)` - Checks if AST node is React.createElement\n- `argumentJsx(argument)` - Checks if AST node is JSX transform output (_jsx, _jsxs)\n- `shouldAddDisplayName(node)` - Checks if a node should have displayName added\n\n## Options\n\n```json\n{\n  \"parseDependencies\": false,\n  \"include\": [],\n  \"exclude\": []\n}\n```\n\n### parseDependencies\n\nType: `boolean`\nDefault: `false`\n\nIf set true, the plugin will name the components exported from node_modules.\n\n### include\n\nType: `(string | RegExp | (path: string) =\u003e boolean)[]` Default: `[]`\n\nIf the path matches any of the elements in this array, it will be included if it isn't explicitly excluded.\n\nIf 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.\n\n### exclude\n\nType: `(string | RegExp | (path: string) =\u003e boolean)[]` Default: `[]`\n\nIf the path matches any of the elements in this array, it will be excluded.\n\nIf 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.\n\nA truthy result will be excluded.\n\n## Troubleshooting\n\nAs you probably know, there is more than one way to define a React component. This\nplugin attempts to detect every possible way of defining a component, but there may\nbe some we've missed. See the `/examples` directory and the unit tests for examples\nof the different permutations of React component definitions that we currently support.\n\nIf we are not detecting one of your components, please either file an Issue containing\nexample source for a component which is not detected, or feel free to open a PR with\nthe fix.\n\n## License\n\nThis project is licensed under the terms of the MIT license. See `LICENSE.md` for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmockingjay-io%2Freact-display-name-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmockingjay-io%2Freact-display-name-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmockingjay-io%2Freact-display-name-plugin/lists"}