# @startupjs/babel-plugin-eliminator

> Cut out specific named exports or do the opposite -- only keep the ones you specify

Latest version **0.63.1** (published 2026-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @startupjs/babel-plugin-eliminator
pnpm add @startupjs/babel-plugin-eliminator
yarn add @startupjs/babel-plugin-eliminator
bun add @startupjs/babel-plugin-eliminator
```

## Health

**Score 50/100 (C)** — status: active.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.63.1 |
| Published | 2026-06-24 |
| First published | 2023-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 109 |
| Author | Pavel Zhukov |
| Maintainers | cray0000, yska, zag2art, fctsvirus, maestro.sc, byshock, anagami, rabbit-abyss, tarlord, nariman322 |
| Keywords | babel, babel-plugin, eliminator, react, react-native |

## Links

- npm: https://www.npmjs.com/package/@startupjs/babel-plugin-eliminator
- Repository: https://github.com/startupjs/startupjs
- Homepage: https://github.com/startupjs/startupjs#readme
- Issues: https://github.com/startupjs/startupjs/issues
- npm.io page: https://npm.io/package/@startupjs/babel-plugin-eliminator

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.63.1 (latest) — 2026-06-24
- 0.64.0-alpha.0 (alpha) — 2026-06-24
- 0.60.0-canary.7 (canary) — 2025-11-12
- 0.56.0-alpha.53 (next) — 2024-03-15
- 0.63.0 — 2026-06-24
- 0.63.0-alpha.0 — 2026-05-04
- 0.62.0 — 2026-05-04
- 0.62.0-alpha.0 — 2026-03-25
- 0.61.0 — 2026-01-02
- 0.60.0-canary.2 — 2025-11-08
- 0.60.0-canary.0 — 2025-11-06
- 0.59.0-canary.12 — 2025-05-29
- 0.59.0-canary.0 — 2024-11-08
- 0.58.0-canary.0 — 2024-11-08
- 0.57.0-canary.75 — 2024-09-23
- … 7 more at https://npm.io/package/@startupjs/babel-plugin-eliminator/versions

## README

# @startupjs/babel-plugin-eliminator

Cut out specific named exports or do the opposite -- only keep the ones you specify

## Install

```bash
npm i @startupjs/babel-plugin-eliminator
```

## Usage

### Removing specific named exports

#### Options:

```json
{
  "plugins": [
    ["@startupjs/babel-plugin-eliminator", {"removeExports": ["foo", "default"]}]
  ]
}
```

#### Input:

```js
import usedByFoo from 'used-by-foo'
import usedByDefault from 'used-by-default'
import usedByBar from 'used-by-bar'

const varInFoo = 'var-in-foo'
const varInDefault = 'var-in-default'
const varInBar = 'var-in-bar'

export const foo = () => {
  return usedByFoo(varInFoo)
}

export default () => {
  return usedByDefault(varInDefault)
}

export function bar () {
  return usedByBar(varInBar)
}
```

#### Output:

```js
import usedByBar from 'used-by-bar'

const varInBar = 'var-in-bar'

export var foo = 1

export default 1

export function bar () {
  return usedByBar(varInBar)
}
```

### Keep only the specified exports

#### Options:

```json
{
  "plugins": [
    ["@startupjs/babel-plugin-eliminator", {"keepExports": ["foo", "default"]}]
  ]
}
```

#### Input:

```js
import usedByFoo from 'used-by-foo'
import usedByDefault from 'used-by-default'
import usedByBar from 'used-by-bar'

const varInFoo = 'var-in-foo'
const varInDefault = 'var-in-default'
const varInBar = 'var-in-bar'

export const foo = () => {
  return usedByFoo(varInFoo)
}

export default () => {
  return usedByDefault(varInDefault)
}

export function bar () {
  return usedByBar(varInBar)
}
```

#### Output:

```js
import usedByFoo from 'used-by-foo'
import usedByDefault from 'used-by-default'

const varInFoo = 'var-in-foo'
const varInDefault = 'var-in-default'

export const foo = () => {
  return usedByFoo(varInFoo)
}

export default () => {
  return usedByDefault(varInDefault)
}

export var bar = 1
```

### Removing Keys within Objects of Magic Function Calls

This feature in the `@startupjs/babel-plugin-eliminator` allows selective retention or removal of keys within objects passed to specific functions. It's particularly useful for customizing the shape of large objects or configurations passed to 'magic' functions.

To utilize this feature, configure the `keepObjectKeysOfFunction` option in your Babel plugin settings. This allows you to specify the functions and the particular keys within their object arguments that you want to keep.

#### Options:

```json
{
  "plugins": [
    [
      "@startupjs/babel-plugin-eliminator",
      {
        "keepObjectKeysOfFunction": {
          "createProject": {
            "magicImports": ["startupjs/registry", "@startupjs/registry"],
            "targetObjectJsonPath": "$.plugins.*",
            "ensureOnlyKeys": ["client", "isomorphic", "server", "build"],
            "keepKeys": ["client", "isomorphic"]
          }
        }
      }
    ]
  ]
}
```

In this configuration:
- `createProject` is the function where object key manipulation occurs.
- `magicImports` specifies the module imports that identify `createProject` as a magic function.
- `targetObjectJsonPath` (optional) is the JSON path to the target object path within the function's first argument. By default the top-level object itself is used.
- `keepKeys` specifies which keys in the object should be retained in the output.
- `ensureOnlyKeys` (optional) lists all possible keys in the object, providing a way to validate the object structure.

#### Input

```js
import { createProject } from 'startupjs/registry'

// ...other imports...

export default createProject({
  plugins: {
    'serve-static-promo': {
      client: {
        redirectUrl: '/promo',
        // ...other client properties...
      },
      server: {
        // ...server properties...
      },
      build: {
        // ...build properties...
      },
      isomorphic: {
        // ...isomorphic properties...
      }
    },
    permissions: {
      client: {
        // ...permissions client properties...
      },
      server: {
        // ...permissions server properties...
      },
      build: {
        // ...permissions build properties...
      },
      isomorphic: {
        // ...permissions isomorphic properties...
      }
    }
  }
})
```

#### Output

```js
import { createProject } from "startupjs/registry";

// ...other imports...

export default createProject({
  plugins: {
    "serve-static-promo": {
      client: {
        redirectUrl: "/promo",
        // ...retained client properties...
      },
      isomorphic: {
        // ...retained isomorphic properties...
      }
    },
    permissions: {
      client: {
        // ...retained permissions client properties...
      },
      isomorphic: {
        // ...retained permissions isomorphic properties...
      }
    }
  }
});
```

## Options

```js
type PluginOpts = {
  /** Removing specific named exports (use 'default' for default export) */
  removeExports?: string[],
  /** Keep only these exports (use 'default' for default export) */
  keepExports?: string[],
  /**
   * Specify keys within objects of specific function calls to be kept.
   * Applies to the objects passed as arguments to the specified functions.
   */
  keepObjectKeysOfFunction?: {
    [functionName: string]: {
      /** Array of module import paths which identify the function as a 'magic' function */
      magicImports: string[],
      /** JSON path to the object within the function where the keys are located */
      targetObjectJsonPath?: string,
      /** List of all possible keys within the object (for validation purposes) */
      ensureOnlyKeys?: string[],
      /** Array of keys that should be kept in the final output */
      keepKeys: string[]
    }
  }
}
```

## Credits

This plugin is a fork of [egoist/babel-plugin-eliminator](https://github.com/egoist/babel-plugin-eliminator) with the following changes:

1. refactor to pure JS
2. rename `namedExports` to `removeExports`
3. add an alternative `keepExports` option. If specified, only these ones are gonna be kept and all other exports will be removed
4. handle `default` export
5. add feature to remove object keys within magic function calls

## License

MIT

---
_Source: https://npm.io/package/@startupjs/babel-plugin-eliminator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
