unplugin-inline-enum
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

unplugin-inline-enum npm jsr

Unit Test

Inline enum values to optimize bundle size.

Features

  • 🚀 Inline enum values to reduce the size of the bundle.
  • 🧹 Simplify generated enums in JavaScript.
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

# npm
npm i -D unplugin-inline-enum

# jsr
npx jsr add -D @unplugin/inline-enum
Vite
// vite.config.ts
import InlineEnum from 'unplugin-inline-enum/vite'

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


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

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


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

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


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


Options

Refer to docs.

Credits

Thanks to @xiaoxiangmoe and @yangmingshan for their contributions in the PR.

Sponsors

License

MIT License © 2024-PRESENT 三咲智子

Package Sidebar

Install

npm i unplugin-inline-enum

Weekly Downloads

3

Version

0.2.0

License

MIT

Unpacked Size

35.3 kB

Total Files

33

Last publish

Collaborators

  • userquin
  • hannoeru
  • sxzz
  • antfu