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
- Host: GitHub
- URL: https://github.com/sanketmaru/babel-plugin-mobile-optimizer-react
- Owner: sanketmaru
- License: mit
- Created: 2019-06-23T06:46:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-06T03:10:30.000Z (about 2 years ago)
- Last Synced: 2024-12-04T16:49:37.665Z (6 months ago)
- Language: JavaScript
- Size: 43.9 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### babel-plugin-mobile-optimizer-react
[](https://travis-ci.org/sanketmaru/babel-plugin-mobile-optimizer-react)
[](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)