Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abskrj/babel-plugin-function-injection
https://github.com/abskrj/babel-plugin-function-injection
babel hacktoberfest hacktoberfest-accepted hacktoberfest2021 js plugin
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/abskrj/babel-plugin-function-injection
- Owner: abskrj
- Created: 2021-10-08T07:32:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-08T13:00:50.000Z (over 3 years ago)
- Last Synced: 2024-11-26T12:36:39.410Z (about 2 months ago)
- Topics: babel, hacktoberfest, hacktoberfest-accepted, hacktoberfest2021, js, plugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/babel-plugin-function-injection
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
babel-plugin-function-injection 👋
> A Babel plugin to inject and wrap a function on an exported object
### 🏠 [Homepage](https://github.com/abhishekraj272/babel-plugin-function-injection#readme)
## Prerequisites
- npm >=1.0.0
- node >=1.0.0## Install
```sh
yarn add -D babel-plugin-function-injection--OR--
npm i -D babel-plugin-function-injection
```## Usage
You need to pass 2 keys to the plugin options.
```js
{
imports: IImport[],
target: RegEx // Files need to be injected
}interface IImport {
name: string;
lib: string;
defaultImport: boolean;
}
```## Example
```js
// Pluginmodule.exports = function (api) {
api.cache(true);const plugins = [
[
"babel-plugin-function-injection",
{
imports: [
{
name: "connect",
lib: "react-redux",
defaultImport: false,
},
{
name: "mapStateToProps",
lib: "@utils/stateToProps",
defaultImport: true,
},
],
target: /(.*components.*index.[js|mjs|jsx|ts|tsx]*)/,
},
],
];return {
plugins,
};
};// Result
// File: components/index.js
// Input --> to plugin
export { default } from './Navbar';
----
export default Navbar;
// Output <-- from plugin
import { connect } from "react-redux";
import mapStateToProps from "@utils/stateToProps";export const Something = connect(mapStateToProps)(Component);
----
export default connect(mapStateToProps)(Navbar);
```## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/abhishekraj272/babel-plugin-function-injection/issues). You can also take a look at the [contributing guide]( ).## Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2021 [Abhishek Raj](https://github.com/abhishekraj272).
This project is [MIT](https://github.com/abhishekraj272/babel-plugin-function-injection/blob/master/LICENSE) licensed.***
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_