GithubHelp home page GithubHelp logo

nogsmpls / babel-plugin-transform-react-remove-statics Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 38 KB

Remove unnecessary statics attached to React components for different build environments

License: MIT License

JavaScript 100.00%

babel-plugin-transform-react-remove-statics's Introduction

Babel Plugin for removing statics from React components

Remove unnecessary statics attached to React components for different build environments

Usage

Set the statics you want via babel configuration with boolean.

This can be particularly useful if you want to switch certain statics on/off for certain environments. An example of this would be using something like react-styleguide-generator-alt for your documentation. Since that tool requires you to attach a static styleguide to your components, you probably would want to remove it in production. But you would probably want to keep it to actually build your doc server, and then remove PropTypes still. This babel plugin gives you that flexibility.

Via .babelrc (Recommended)

Simply pass in the name of the static you want removed during build and set a boolean. If true, the static will be removed, if false, the static will stay attached to the component.

.babelrc

{
  "env": {
    "production": {
      "plugins": [
        ["transform-react-remove-statics", {
          "propTypes": true
        }]
      ]
    }
  }
}

Via Node API

require("babel-core").transform("code", {
  plugins: [
    ["transform-react-remove-statics", {
      "propTypes": true
    }]
  ]
});

Example Removing PropTypes

Using a configuration like we showed above, we can remove PropTypes from React Components.

In

const Foo = React.createClass({
  propTypes: {
    foo: React.PropTypes.string
  }
});

Out

const Foo = React.createClass({});

Installation

$ npm install --save-dev babel-plugin-transform-react-remove-statics

#License

MIT

Thanks

This project was originally a fork of Babel Plugin Transform React Remove PropTypes, by oliviertassinari, which is in turn a fork of Babel Plugin React Remove PropTypes by nkt.

Thank you nkt and oliviertassinari for letting me stand on your shoulders.

babel-plugin-transform-react-remove-statics's People

Contributors

bitfrost avatar nogsmpls avatar oliviertassinari avatar strml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

babel-plugin-transform-react-remove-statics's Issues

Aliasing React Modules

Currently defining React's Component class with an alias does not work:

import { Component as reactComp } from "react"

Will not remove statics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.