Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thejameskyle/babel-react-optimize

:rocket: A Babel preset and plugins for optimizing React code.
https://github.com/thejameskyle/babel-react-optimize

Last synced: 3 months ago
JSON representation

:rocket: A Babel preset and plugins for optimizing React code.

Awesome Lists containing this project

README

        

# Babel React Optimize

A Babel preset and plugins for optimizing React code.

## Optimizations

### [`transform-react-constant-elements`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-constant-elements)

**Input:**

```js
class MyComponent extends React.Component {
render() {
return (


Hello World

);
}
}
```

**Output:**

```js
var _ref = Hello World;

class MyComponent extends React.Component {
render() {
return (


{_ref}

);
}
}
```

### [`transform-react-inline-elements`](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-inline-elements)

**Input:**

```js
class MyComponent extends React.Component {
render() {
return (


Hello World

);
}
}
```

**Output:**

```js
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`](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types)

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

render() {
return (


Hello World

);
}
}
```

**Output:**

```js
class MyComponent extends React.Component {
render() {
return (


Hello World

);
}
}
```

### [`transform-react-pure-class-to-function`](https://github.com/thejameskyle/babel-react-optimize/tree/master/packages/babel-plugin-transform-react-pure-class-to-function)

**Input:**

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

render() {
return (


Hello World

);
}
}
```

**Output:**

```js
function MyComponent(props) {
return (


Hello World

);
}

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

## Install

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

## Usage

`.babelrc`

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

## Benchmarks

We haven't yet much benchmark.
But this [post](https://medium.com/doctolib-engineering/improve-react-performance-with-babel-16f1becfaa25)
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.