https://github.com/egoist/babel-plugin-eliminator
A babel plugin to remove specific named exports and more
https://github.com/egoist/babel-plugin-eliminator
Last synced: 10 months ago
JSON representation
A babel plugin to remove specific named exports and more
- Host: GitHub
- URL: https://github.com/egoist/babel-plugin-eliminator
- Owner: egoist
- License: mit
- Created: 2021-03-14T16:17:53.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-25T14:09:35.000Z (about 4 years ago)
- Last Synced: 2025-05-03T21:09:10.916Z (10 months ago)
- Language: TypeScript
- Size: 53.7 KB
- Stars: 25
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - babel-plugin-eliminator
README
# babel-plugin-eliminator
## What is this?
This is a babel plugin for removing specific named exports in your JavaScript code, this is how Next.js implements `getServerSideProps` and `getStaticProps`, it essentially removes thoses exports and referenced variables.
## Install
```bash
npm i babel-plugin-eliminator
```
## Usage
### Removing specific named exports
Options:
```json
{
"plugins": [
["eliminator", {"namedExports": ["foo"]}]
]
}
```
Input:
```ts
import pkg from 'some-pkg'
const someVariable = 'some-string'
export const foo = () => {
return pkg(someVariable)
}
```
Output:
```ts
export var foo = 1
```
## Options
```ts
type PluginState = {
refs: Set>
opts: PluginOpts
/** Removed named exports */
removedNamedExports: Set
}
type PluginOpts = {
/** Removing specific named exports */
namedExports?: string[]
/** Called at the end of transpiling */
done?: (state: PluginState) => void
}
```
## Credits
This plugin is essentially a fork of [next.js/next-ssg-transform](https://github.com/vercel/next.js/blob/574fe0b582d5cc1b13663121fd47a3d82deaaa17/packages/next/build/babel/plugins/next-ssg-transform.ts).
## License
MIT © [EGOIST](https://github.com/sponsors/egoist)