A Babel plugin to remove JSX attributes.
yarn add -D babel-plugin-jsx-remove-attributes
In .babelrc
add the plugin and inform your list of attributes to be removed. (You can pass Strings or RegExp)
{
plugins: [
...
[
"babel-plugin-jsx-remove-attributes", {
attributes: ["attribute1", /attribute2/, ...]
}
]
...
]
}
Input JSX Component
const Component = () => (
<h1 className="title" data-test-id="title" data-effect-active="true">Hello World!</h1>
)
Config plugin
{
plugins: [
...
[
"babel-plugin-jsx-remove-attributes", {
attributes: ["data-test-id", /data-effect.*/]
}
]
...
]
}
Output JSX Component
const Component = () => (
<h1 className="title">Hello World!</h1>
)