npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rollup-plugin-const-enum

v1.1.4

Published

A simple plugin to inline your const enums in typescript projects.

Readme

rollup-plugin-const-enum

npm version npm downloads License: MIT Codacy Badge

A tiny Rollup plugin that inlines TypeScript const enum members by simple RegExp-based text replacement. (for example Colors.Red -> 0 or Consts.Key -> "val").

This plugin will replace all occurrences of EnumName.Member in the source files (be aware of the name collision!), then the import statements will be removed by Rollup's tree-shaking.

More Rollup Plugins you might be interested in:

For more awesome packages, check out my homepage💛

ChangeLog

Install

Use pnpm to install as a devDependency:

pnpm add -D rollup-plugin-const-enum

Quick usage

Place the plugin in your Rollup config (near the front of the plugin list is recommended):

import { constEnum } from 'rollup-plugin-const-enum';

export default {
  // ...
  plugins: [
    constEnum(), // place it near the front
    ...
  ],
};

Options

The plugin accepts an optional options object. All options are optional and have sensible defaults.

  • suffixes: string[] — File suffixes to include when scanning the project for const enums. Default: ['.ts', '.tsx', '.mts', '.cts'].
  • files: string[] — Explicit list of file paths (relative to process.cwd()) to scan for const enum declarations. When this array is non-empty the plugin will only use these files (each path is resolved with path.join(process.cwd(), file)) and will ignore recursive directory collection. Default: [] (scan the project tree).
  • excludedDirectories: string[] — Directory names (relative to the project root) to exclude from recursive scanning. Each name is resolved against process.cwd(). Default: ['.git', 'test', 'tests', 'dist', 'node_modules'].
  • skipDts: boolean — When true, files ending with .d.ts are ignored. Default: true.

Validation: suffixes, files, and excludedDirectories must be arrays of strings. Passing invalid types will throw a TypeError during plugin initialization.

Example

import constEnum from 'rollup-plugin-const-enum';

export default {
  plugins: [
    constEnum({
      suffixes: ['.ts', '.tsx'],
      files: ['src/index.ts'],
      excludedDirectories: ['.git', 'node_modules'],
      skipDts: true,
    }),
  ],
};

Important notes

  • Scans and collects all const enums and applies them to every included file.
    • Cannot scan a specific file and apply it to another specific file.
  • This plugin does not use any AST transformer.
  • Replacements are based on the textual key EnumName.Member using RegExp.
  • Only supports simple cases. Ambiguous or complex expressions are not supported.

Advanced Usage

You can access the internal replacement list (for advanced use cases) via the plugin instance:

const plugin = constEnum();
const list = plugin.__kskb_replacement_list; // [ [RegExp, [ [key, value], ... ] ], ... ]

License

MIT