1.0.1 • Published 2 years ago

babel-plugin-remove-unuse-code v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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,
        }
      }
    ]
  ]
}