# vite-plugin-remove-exports

> My awesome typescript library

Latest version **1.1.0** (published 2021-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-remove-exports
pnpm add vite-plugin-remove-exports
yarn add vite-plugin-remove-exports
bun add vite-plugin-remove-exports
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-12-01 |
| First published | 2021-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | egoist |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-remove-exports
- npm.io page: https://npm.io/package/vite-plugin-remove-exports

## Dependencies (2)

- [esbuild](https://npm.io/package/esbuild.md) ^0.14.1
- [es-module-lexer](https://npm.io/package/es-module-lexer.md) ^0.9.3

## Recent versions

- 1.1.0 (latest) — 2021-12-01
- 1.0.0 — 2021-12-01

## README

**💛 You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/egoist).**

---

# vite-plugin-remove-exports

[![npm version](https://badgen.net/npm/v/vite-plugin-remove-exports)](https://npm.im/vite-plugin-remove-exports) [![npm downloads](https://badgen.net/npm/dm/vite-plugin-remove-exports)](https://npm.im/vite-plugin-remove-exports)

## Use Case

It's useful if you want to implement something like Next.js' `getServerSideProps` or the `loader` function from Remix.js. This is done by creating a proxy of your code with the exports you specfied excluded and using esbuild to bundle the proxy code in order to eliminate unneeded exports.

Despite that we added an extra step to the build process, the plugin is still very fast due the how fast esbuild is.

## Install

```bash
npm i vite-plugin-remove-exports
```

## Usage

`vite.config.ts`:

```ts
export default {
  plugins: [
    removeExports({
      match() {
        return ['getServerSideProps']
      },
    }),
  ],
}
```

Now if you have a `index.tsx`:

```tsx
import fs from 'fs'

export const getServerSideProps = () => {
  return {
    content: fs.readFileSync('./foo.txt', 'utf-8'),
  }
}

export default ({ content }) => {
  return <div>{content}</div>
}
```

The output will be:

```tsx
export default ({ content }) => {
  return <div>{content}</div>
}
```

Advanced usage:

```ts
removeExports({
  match(filepath, ssr) {
    // Ignore SSR build
    if (!ssr) return

    // Remove getServerSideProps in "pages" in browser build
    if (filepath.startsWith(pagesDir)) {
      return ['getServerSideProps']
    }
  },
}),
```

## Caveats

- `export *` is not supported.
- When using both Vue's `<script setup>` and `<script>` tags in a single file, the imports in regular `<script>` tags can't be removed even if they're only used in removed exports.

## Sponsors

[![sponsors](https://sponsors-images.egoist.sh/sponsors.svg)](https://github.com/sponsors/egoist)

## License

MIT &copy; [EGOIST](https://github.com/sponsors/egoist)

---
_Source: https://npm.io/package/vite-plugin-remove-exports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
