Skip to content

Use babel-plugin-transform-react-remove-prop-types for build:node task#463

Merged
gpbl merged 1 commit intogpbl:masterfrom
oigewan:babel
Jul 19, 2017
Merged

Use babel-plugin-transform-react-remove-prop-types for build:node task#463
gpbl merged 1 commit intogpbl:masterfrom
oigewan:babel

Conversation

@oigewan
Copy link

@oigewan oigewan commented Jul 19, 2017

Feature:
Fixes #462

This will wrap all assignments to the propTypes property of a React component class in a process.env.NODE_ENV !== "production", which will allow npm module consumers to remove prop types for their production build. This will allow for smaller deployables for consumers.

Known Issue:
This will require users to inject the value for process.env.NODE_ENV. Consumers can do this via webpack's Environment Plugin or rollup's Replace Plugin.

Changes:
Add transform-react-remove-prop-types to the .babelrc file with the mode set to "wrap". Output will end up looking like this:

exports.default = Caption;
Caption.propTypes = process.env.NODE_ENV !== "production" ? {
  date: _propTypes2.default.instanceOf(Date),
  months: _propTypes2.default.arrayOf(_propTypes2.default.string),
  locale: _propTypes2.default.string,
  localeUtils: _propTypes2.default.object,
  onClick: _propTypes2.default.func,
  classNames: _propTypes2.default.shape({
    caption: _propTypes2.default.string.isRequired
  }).isRequired
} : {};

cc: @gpbl

@codecov
Copy link

codecov bot commented Jul 19, 2017

Codecov Report

Merging #463 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #463   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines         527    527           
  Branches      109    109           
=====================================
  Hits          527    527

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a05d673...f732f1e. Read the comment docs.

@gpbl gpbl merged commit fce0368 into gpbl:master Jul 19, 2017
@gpbl
Copy link
Owner

gpbl commented Jul 19, 2017

thanks!

@gpbl gpbl added this to the v6.1.1 milestone Jul 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants