项目
在 GitHub 查看
jamiebuilds/babel-react-optimize
关于
:rocket: 用于优化 React 代码的 Babel 预设和插件。
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- -1
- 1个月
- -3
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
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-runtimeandbabel-transform-runtimeto 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.
探索相关项目
加载中…