npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-preset-react-plus

v1.3.0

Published

Babel preset for react development with some additional ECMAScript propersal based on babel-preset-react

Downloads

32

Readme

babel-preset-react-plus

npm version npm downloads dependencies

Babel preset for react development with some additional ECMAScript propersal based on babel-preset-react.

NOTE:

- Requires Babel v6+.
- babel-preset-es2015/es2016/es2017/latest are excluded. You need to download them manually.
- async/await was offically moved into babel-preset-es2017.

Install

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

Introdcution

This preset includes the following ECMAScript propersals:

Since above five are becoming the most frequently used propersals in react apps I decide to intergrate them into one preset which also includes the basic babel-preset-react. ~~so that we no longer need to download them separately and enable these propersals by downloading corresponding syntax-parsing plugins manually. Except this you can also download babel-preset-stage-* together with those syntax-parsing plugins but it is unconvenient and includes some other transform modules you'll probably never use~~. Recently babel finally integrated their transform plugins with the corresponding syntax-parsing plugins thus we no longer need to download them separately. However I still think this preset useful since the stage of propersals always change frequently which means it's hard to decide which preset-stage plugin should choose.

Internal presets and plugins

Boilerplate

decorators

react-redux

import React, { Component } from 'react';
import { connect } from 'react-redux';

@connect(
  state => ({ todos: state.todos }),
  actionCreators
)
class App extends Component {
  ...
}

export default App;

react-router

import React, { Component } from 'react';
import { withRouter } from 'react-router';

@withRouter
class App extends Component {
  ...
}

export default App;

core-decorators

import React, { Component } from 'react';
import { autobind } from 'core-decorators';

@autobind
class App extends Component {
  // You don't have to set this.handleClick.bind(this) in
  // constructor or the place where it's being called
  handleClick() {...}
  ...
}

export default App;

class-properties

import React, { Component } from 'react';

class App extends Component {
  state = {}

  handleClick = (e) => {
    
  }
  ...
}

export default App;

object-spread-rest

// Sometimes useful in redux

// reducer
const users = (state = {}, action) => {
  switch(action.type) {
    case "ADD_USER": {
      return {
        ...state,
        [action.id] = action.info
      }
    }
    ...
  }
}

export-extensions

// It's a common pattern which separates React components into corresponding files 
// And we need to create a index.js to export all imported components

// Before
import A from './a';
import B from './b';
import C from './c';
import { foo, bar } from './utils';

export { A, B, C, foo, bar };
//or
export { default as A } from './a';
export { default as B } from './b';
export { default as C } from './c';
export { foo, bar } from './utils';

// After
export A from './a';
export B from './b';
export C from './c';
export * as utils from './utils';

Usage

Via .babelrc (Recommended)

.babelrc

{
  "presets": ["react-plus"]
}

Via CLI

$ babel script.js --presets react-plus

Via Node API

require("babel-core").transform("code", {
  presets: ["react-plus"]
});