@jacobp100/babel-plugin-react-displayname-path

2.0.1 • Public • Published

babel-plugin-react-displayname-path

Part of the TechniCalc Project

Babel plugin to display React components names with file path prefix. Automatically detects and sets displayName property for React components.

This is useful for having meaningful component names show up in production builds of React apps.

This will work for top level functions that return JSX.

  • Function declarations via functionName.displayName = 'DisplayName'
  • Arrow functions and function expressions via Object.assign(() => {...}, { displayName: 'DisplayName' })

Class components are not supported.

Install

  • yarn add @jacobp100/babel-plugin-react-displayname-path
  • Add @jacobp100/react-displayname-path to your babel.config.js file:
const plugins = ["@jacobp100/react-displayname-path"];

Troubleshooting

If displayName isn't added, make sure the plugin placed before other plugins in your plugins list.

Motivation

Component stack traces are useless in production build:

    in b
    in li
    in ul
    in v
    in div
    in div
    in i
    in div
    in Unknown
    in t…

Readme

Keywords

none

Package Sidebar

Install

npm i @jacobp100/babel-plugin-react-displayname-path

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

7.23 kB

Total Files

4

Last publish

Collaborators

  • jacobp100