# babel-plugin-transform-replace-export-default

> Replace `export default` with `return`, or just remove `export default`.

Latest version **1.0.4** (published 2022-05-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-replace-export-default
pnpm add babel-plugin-transform-replace-export-default
yarn add babel-plugin-transform-replace-export-default
bun add babel-plugin-transform-replace-export-default
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-05-12 |
| First published | 2022-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jaywcjlove |
| Maintainers | wcjiang |
| Keywords | babel, babel-plugin-transform, babel-plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-replace-export-default
- Repository: https://github.com/kktjs/babel-plugin-transform-replace-export-default
- Homepage: https://kktjs.github.io/babel-plugin-transform-replace-export-default
- Issues: https://github.com/kktjs/babel-plugin-transform-replace-export-default/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-replace-export-default

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2022-05-12
- 1.0.3 — 2022-05-12
- 1.0.2 — 2022-05-12
- 1.0.1 — 2022-05-12
- 1.0.0 — 2022-05-12

## README

<!--idoc:ignore:start-->
babel-plugin-transform-replace-export-default
===
<!--idoc:ignore:end-->

[![NPM version](https://img.shields.io/npm/v/babel-plugin-transform-replace-export-default.svg?style=flat)](https://npmjs.org/package/babel-plugin-transform-replace-export-default)
[![CI](https://github.com/kktjs/babel-plugin-transform-replace-export-default/actions/workflows/ci.yml/badge.svg)](https://github.com/kktjs/babel-plugin-transform-replace-export-default/actions/workflows/ci.yml)
[![Coverage Status](https://kktjs.github.io/babel-plugin-transform-replace-export-default/coverage/badges.svg)](https://kktjs.github.io/babel-plugin-transform-replace-export-default/coverage/lcov-report)
[![Downloadss](https://img.shields.io/npm/dm/babel-plugin-transform-replace-export-default.svg?style=flat)](https://npmjs.org/package/babel-plugin-transform-replace-export-default)

Replace `export default` with `return`, or just remove `export default`.

## Usage

```bash
npm install babel-plugin-transform-replace-export-default --save-dev
```

Via `.babelrc` or `babel-loader`.

```json
{
  "plugins": [
    "babel-plugin-transform-replace-export-default"
  ]
}
```

Or

```json
{
  "plugins": [
    ["babel-plugin-transform-replace-export-default", {
      "removeExportDefault": true
    }]
  ]
}
```


## Replace `export default` to `return`

### Example 1

```js
// Input Code
const demo = 0;
export default demo;

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
const demo = 0;
return demo;
```

Output Result

```diff
const demo = 0;
- export default demo;
+ return demo;
```

### Example 2

```js
// Input Code
function demo() {};
export default demo;

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
function demo() {};
return demo;
```

Output Result

```diff
function demo() {};
- export default demo;
+ return demo;
```

### Example 3

```js
// Input Code
class demo { constructor() { } };
export default demo;

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
class demo { constructor() { } };
return demo;
```

Output Result

```diff
class demo { constructor() { } };
- export default demo;
+ return demo;
```

### Example 4

```js
// Input Code
export default class demo { constructor() { } };

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
return class demo { constructor() { } };
```

Output Result

```diff
- export default class demo { constructor() { } };
+ return class demo { constructor() { } };
```

### Example 5

```js
// Input Code
export default class demo { constructor() { } };

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
return class demo { constructor() { } };
```

Output Result

```diff
- export default function demo() {};
+ return function demo() {};
```

## Remove `export default`

```json
{
  "plugins": [
    ["babel-plugin-transform-replace-export-default", {
      "removeExportDefault": true
    }]
  ]
}
```

### Example 1

```js
// Input Code
export default class demo {}

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
class demo {}
```

Output Result

```diff
- export default class demo {}
+ class demo {}
```

### Example 2

```js
// Input Code
export default function demo() {}

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
function demo() {}
```

Output Result

```diff
- export default function demo() {}
+ function demo() {}
```

### Example 3

```js
// Input Code
class demo {}
export default demo;

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
class demo {}
```

Output Result

```diff
class demo {}
- export default demo;
```

### Example 4

```js
// Input Code
function demo() {}
export default demo;

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
function demo() {}
```

Output Result

```diff
function demo() {}
- export default demo;
```

### Example 5

```js
// Input Code
const demo = 0;
export default demo;

// 👇👇👇 Output   ↓ ↓ ↓ ↓ ↓ ↓
const demo = 0;
```

Output Result

```diff
const demo = 0;
- export default demo;
```


## Programmatic Usage

```js
import plugin from 'babel-plugin-transform-replace-export-default';
import { transformSync } from '@babel/core';
 
function replace(code) {
  return transformSync(code, {
    babelrc: false,
    plugins: [
      [plugin, {
        removeExportDefault: true
      }]
    ],
  }).code;
}
 
replace("export default function demo() {}");
//=> "function demo() {}"
```

## Related

- [markdown-react-code-preview-loader](https://github.com/kktjs/markdown-react-code-preview-loader)
- [babel-plugin-transform-remove-imports](https://github.com/uiwjs/babel-plugin-transform-remove-imports)

## Contributors

As always, thanks to our amazing contributors!

<a href="https://github.com/kktjs/babel-plugin-transform-replace-export-default/graphs/contributors">
  <img src="https://kktjs.github.io/babel-plugin-transform-replace-export-default/CONTRIBUTORS.svg" />
</a>

Made with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors).

## License

MIT © [`Kenny Wong`](https://github.com/jaywcjlove)


<!--idoc:config:
footer: |
  Released under the MIT License. Copyright © 2022 Kenny Wong<br />
  Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a> v{{idocVersion}}
-->

---
_Source: https://npm.io/package/babel-plugin-transform-replace-export-default · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
