npm install --save-dev babel-plugin-remove-react-jsx-attribute
yarn add -D babel-plugin-remove-react-jsx-attribute
This is useful to remove the JSX attribute which isn't necessary to transpile. For instance, You can easily remove 'data-testid' just for testing.
- input
function Element() {
return <div className="app" data-testid="custom-element" />;
}
- output
function Element() {
return <div className="app" />;
}
Add plugin to .babelrc
or webpack.config.js babel options
The format of attributes should be consist of string or regular expression.
plugins: [
...
["babel-plugin-remove-react-jsx-attribute", { attributes: ["data-testid", /^(data-)/]}]
]