0.1.0 • Published 4 years ago

remove-data-cy.macro v0.1.0

Weekly downloads
22
License
ISC
Repository
github
Last release
4 years ago

remove-data-cy.macro

Babel macro for removing data-cy attributes from JSX Elements\ Usable with CRA versions >= 2.0

This package is highly experimental, intended for use in my own projects. Use with caution. In it's current stage it can only remove data-cy attributes which are strings. Anything else, such as dynamic data-cy values(a function for example) will probably cause an error.

Install

Using npm:

npm install --save-dev remove-data-cy.macro

or using yarn:

yarn add remove-data-cy.macro --dev

Usage

import rdc from "remove-data-cy.macro";
<div {...rdc`data-cy='welcome-message'`}>Hello!</div>

Results in

Production environment:
<div>Hello!</div>

Every other environment:
<div data-cy='welcome-message'>Hello!</div>

Production environemtn is determined by

process.env.NODE_ENV == "production" ||
process.env.REACT_APP_CUSTOM_ENV == "prod" ||
process.env.REACT_APP_CUSTOM_ENV == "production"

These values should be in a .env file at the root of your project(where your package.json is).

CRA automatically sets NODEENV to 'production', 'development' or 'test'_ for respectively yarn build, yarn start and yarn test