GithubHelp home page GithubHelp logo

babel-plugin-remove-unuse-code's Introduction

babel-plugin-remove-unuse-code

删除无用if判断

In:

if (isWeb){
	console.log(1);
} else {
	console.log(2);
}

Out:

console.log(1);

删除无用变量

In:

import { Text, View, StyleSheet, Image } from 'react-native';
const Index = () => {
    return <Text>test</Text>
}
const st = StyleSheet.create({

})

Out:

import { Text,StyleSheet } from 'react-native';
const Index = () => {
    return <Text>test</Text>
}
const st = StyleSheet.create({

})

删除propTypes

In:

import React from 'react';
import PropTypes from 'prop-types';
const Index = () => {
    return 1
}
Index.propTypes = {
    text: PropTypes.string
}

Out:

import React from 'react';
const Index = () => {
    return 1
}

In:

import React from 'react';
import PropTypes from 'prop-types';
class App extends React.PureComponent {
    static propTypes = {
        text: PropTypes.string
    }
    render() {
        return null
    }
}

Out:

import React from 'react';
class App extends React.PureComponent {
    render() {
        return null
    }
}

删除console,debugger

In:

import React from 'react';
const Index = () => {
    var a = 1;
    console.log(1);
    debugger;
    return 1
}

Out:

import React from 'react';
const Index = () => {
    var a = 1;
    return 1
}

Install

npm install --save-dev babel-plugin-remove-unuse-code

Usage

.babelrc

{
  "plugins": [
    [
      "remove-unuse-code",
      {
        "isRelease": true,
        "var": {
          "isWeb": true,
          "isAndroid": false,
          "isIOS": false,
        },
        "imports": {
          "ignoreLibraries": ["react"],
          "remove": true,
        },
        "propTypes": {
          "remove": true,
          "onlyProduction": false,
        }
      }
    ]
  ]
}

babel-plugin-remove-unuse-code's People

Contributors

aih5 avatar

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.