babel-plugin-ot-ignore

0.0.6 • Public • Published

babel-plugin-ot-ignore

A Babel plugin that adds configurable data-ot-ignore='' and className='optanon-category-C0001' to all React elements (script, img, iframe, embed...) which have src attribute.

Installation

npm i babel-plugin-ot-ignore

Or

yarn add babel-plugin-ot-ignore

Usage

Add to your .babelrc file:

{
  "plugins": ["babel-plugin-ot-ignore"]
}

If you want to pass custom configuration options use .babelrc.js

module.exports = function (api) {
  ...

  const plugins = [
    ...
    [
      'babel-plugin-ot-ignore',
      {
        otDataAttribute: "data-ot-ignore",
        otClassName: "optanon-category-C0001",
        srcValueRegex: /^https:\/\/yoursite.com/,
      },
    ],
    ...
  ];

  return {
    ...
    plugins,
    ...
  };
};

Example

This jsx code:

  const MyComponent = () => (
    <div>
      <img src="http://placekitten.com/200/300" />
    </div>
  );

Will be transformed to:

  const MyComponent = () => (
    <div>
      <img src="http://placekitten.com/200/300" data-ot-ignore="" className="optanon-category-C0001" />
    </div>
  );

Package Sidebar

Install

npm i babel-plugin-ot-ignore

Weekly Downloads

793

Version

0.0.6

License

MIT

Unpacked Size

13.9 kB

Total Files

5

Last publish

Collaborators

  • zzzarius