Add modulePath
to React components instantiated in ES6 style inheriting from React.Component (ex: class ComponentName extends React.Component
or class ComponentName extends React.Component
).
modulePath
represents the modules location on the filesystem. Good as an alternative to React displayName
, when name collisions are likely.
$ npm install babel-plugin-transform-react-es6-displayname
.babelrc
{
"plugins": ["transform-react-es6-displayname"]
}
or with options:
{
"plugins": [
["transform-react-es6-displayname", {stripCwd: true, stripExtension: true}]
]
}
$ babel --plugins transform-react-es6-displayname script.js
require("babel-core").transform("code", {
plugins: ["transform-react-es6-displayname"]
});
stripCwd
[boolean] - Whether to strip current working folder frommodulePath
(cwd is fromprocess.cwd()
)stripExtension
[boolean] - Whether to strip extensions frommodulePath
Read babel plugin handbook -> https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md
To run tests, run npm test
or npm test watch