An open API service indexing awesome lists of open source software.

https://github.com/unplugin/unplugin-inline-enum

Inline enum values to optimize bundle size.
https://github.com/unplugin/unplugin-inline-enum

Last synced: 4 days ago
JSON representation

Inline enum values to optimize bundle size.

Awesome Lists containing this project

README

          

# unplugin-inline-enum

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![jsr][jsr-src]][jsr-href]
[![Unit Test][unit-test-src]][unit-test-href]

Inline enum values to optimize bundle size.

## Features

- ๐Ÿš€ Inline enum values to reduce the size of the bundle.
- ๐Ÿงน Simplify generated enums in JavaScript.

```ts
export enum TestEnum {
a = 1,
b = 'foo',
}
console.log(TestEnum.a, TestEnum.b)

// before
export let TestEnum
;(function (TestEnum) {
TestEnum[(TestEnum.a = 1)] = 'a'
TestEnum.b = 'foo'
})(TestEnum || (TestEnum = {}))

console.log(TestEnum.a, TestEnum.b)

// after
const TestEnum = {
a: 1,
'1': 'a',
b: 'foo',
}
console.log(1, 'foo')
```

## Installation

```bash
# npm
npm i -D unplugin-inline-enum

# jsr
npx jsr add -D @unplugin/inline-enum
```

Vite

```ts
// vite.config.ts
import InlineEnum from 'unplugin-inline-enum/vite'

export default defineConfig({
plugins: [InlineEnum()],
})
```


Rollup

```ts
// rollup.config.js
import InlineEnum from 'unplugin-inline-enum/rollup'

export default {
plugins: [InlineEnum()],
}
```


Rolldown

```ts
// rolldown.config.js
import InlineEnum from 'unplugin-inline-enum/rolldown'

export default {
plugins: [InlineEnum()],
}
```


esbuild

```ts
// esbuild.config.js
import { build } from 'esbuild'

build({
plugins: [require('unplugin-inline-enum/esbuild')()],
})
```


Webpack

```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [require('unplugin-inline-enum/webpack')()],
}
```


## Options

Refer to [docs](https://jsr.io/@unplugin/inline-enum/doc/api/~/Options).

## Credits

Thanks to [@xiaoxiangmoe](https://github.com/xiaoxiangmoe) and
[@yangmingshan](https://github.com/yangmingshan) for their contributions in the
[PR](https://github.com/vuejs/core/pull/9261).

## Sponsors





## License

[MIT](./LICENSE) License ยฉ 2024-PRESENT [Kevin Deng](https://github.com/sxzz)

[npm-version-src]: https://img.shields.io/npm/v/unplugin-inline-enum.svg
[npm-version-href]: https://npmjs.com/package/unplugin-inline-enum
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-inline-enum
[npm-downloads-href]: https://www.npmcharts.com/compare/unplugin-inline-enum?interval=30
[jsr-src]: https://jsr.io/badges/@unplugin/inline-enum
[jsr-href]: https://jsr.io/@unplugin/inline-enum
[unit-test-src]: https://github.com/unplugin/unplugin-inline-enum/actions/workflows/unit-test.yml/badge.svg
[unit-test-href]: https://github.com/unplugin/unplugin-inline-enum/actions/workflows/unit-test.yml