πŸš€ A Babel preset and plugins for optimizing React code.
JavaScript
Latest commit 9afce7a Jul 22, 2016 @avindra avindra committed with .babelrc: πŸ”₯ duplicate presets from production (#13)
Remove presets that were already defined in the base configuration.
Permalink
Failed to load latest commit information.
packages Fix broken urls (#21) Jul 4, 2016
.babelrc Init commit Apr 16, 2016
.eslintrc Init commit Apr 16, 2016
.gitignore Init commit Apr 16, 2016
LICENSE.md Init commit Apr 16, 2016
README.md .babelrc: πŸ”₯ duplicate presets from production (#13) Jul 21, 2016
gulpfile.babel.js Init commit Apr 16, 2016
package.json Init commit Apr 16, 2016

README.md

Babel React Optimize

A Babel preset and plugins for optimizing React code.

Optimizations

transform-react-constant-elements

Input:

class MyComponent extends React.Component {
  render() {
    return (
      <div className={this.props.className}>
        <span>Hello World</span>
      </div>
    );
  }
}

Output:

var _ref = <span>Hello World</span>;

class MyComponent extends React.Component {
  render() {
    return (
      <div className={this.props.className}>
        {_ref}
      </div>
    );
  }
}

transform-react-inline-elements

Input:

class MyComponent extends React.Component {
  render() {
    return (
      <div className={this.props.className}>
        <span>Hello World</span>
      </div>
    );
  }
}

Output:

class MyComponent extends React.Component {
  render() {
    return (
      _jsx('div', { className: this.props.className }, void 0,
        _jsx('span', {}, void 0, 'Hello World')
      )
    );
  }
}

Note: You should use this with babel-runtime and babel-transform-runtime to avoid duplicating the helper code in every file.

transform-react-remove-prop-types

Input:

class MyComponent extends React.Component {
  static propTypes = {
    className: React.PropTypes.string.isRequired
  };

  render() {
    return (
      <div className={this.props.className}>
        <span>Hello World</span>
      </div>
    );
  }
}

Output:

class MyComponent extends React.Component {
  render() {
    return (
      <div className={this.props.className}>
        <span>Hello World</span>
      </div>
    );
  }
}

transform-react-pure-class-to-function

Input:

class MyComponent extends React.Component {
  static propTypes = {
    className: React.PropTypes.string.isRequired
  };

  render() {
    return (
      <div className={this.props.className}>
        <span>Hello World</span>
      </div>
    );
  }
}

Output:

function MyComponent(props) {
  return (
    <div className={props.className}>
      <span>Hello World</span>
    </div>
  );
}

MyComponent.propTypes = {
  className: React.PropTypes.string.isRequired
};

Install

$ npm install --save-dev babel-preset-react-optimize

Usage

.babelrc

{
  "presets": ["es2015", "react"],
  "env": {
    "production": {
      "presets": ["react-optimize"]
    }
  }
}

Benchmarks

We haven't yet much benchmark. But this post can give you an idea of what you can win in real life. Notice that the win depends a lot on how you are using the React API.