An open API service indexing awesome lists of open source software.

https://github.com/sanketmaru/babel-plugin-mobile-optimizer-react

An experimental babel plugin which removes class methods and JSX elements based on the condition passed
https://github.com/sanketmaru/babel-plugin-mobile-optimizer-react

Last synced: 6 months ago
JSON representation

An experimental babel plugin which removes class methods and JSX elements based on the condition passed

Awesome Lists containing this project

README

        

### babel-plugin-mobile-optimizer-react
[![Build
Status](https://api.travis-ci.org/sanketmaru/babel-plugin-mobile-optimizer-react.svg?branch=master)](https://travis-ci.org/sanketmaru/babel-plugin-mobile-optimizer-react)
[![npm](https://img.shields.io/npm/v/babel-plugin-mobile-optimizer-react.svg?maxAge=3600)](https://www.npmjs.com/package/babel-plugin-mobile-optimizer-react)

 

Babel plugin that removes class methods and JSX elements based on conditions.

Conditions are passed based on env variables which are
 
*JSX_ENV* :- Remove JSX Elements matching with element name.
*CLASS_METHOD_ENV* :- Remove class methods ending with this string

 

#### Example

Condition is that we want to remove desktop related code when viewing the web app in a mobile device.
This plugin helps to remove the code during the build time itself when a chunk is created.

Your `App.js` that contains this code:

```js
export default class App extends Component {

handleClick_mobile() {
console.log("Mobile Handle Click");
}

handleClick_desktop() {
console.log("Desktop handle Click");
}

render() {
return (




Mobile


Web



);
}
}
```

will be transpiled to:

```js
export default class App extends Component {

handleClick_mobile() {
console.log("Mobile Handle Click");
}

render() {
return (




Mobile



);
}
}
```

 

#### You like?

:star: this repo

 

#### License

MIT © [SanketMaru](https://github.com/sanketmaru)