0.1.1 • Published 11 months ago

bun-plugin-consts v0.1.1

Weekly downloads
-
License
CC0-1.0
Repository
gitlab
Last release
11 months ago

bun-plugin-consts

Dependency injection for constants using ECMAScript module import syntax.

import DEBUG from "consts:DEBUG";

Inspired by (and compatible with) rollup-plugin-consts.

Usage

Define your constants

// ./consts.ts

export default {
  DEBUG: process.env.DEBUG === "true",
};

Create type declarations for your constants

Define the type of your constants in a declaration file.

// ./index.d.ts

declare module "consts:DEBUG" {
  const DEBUG: boolean;
  export default DEBUG;
}

Import your constants

import DEBUG from "consts:DEBUG";

console.log(`${DEBUG}`);

Register a plugin with the Bun runtime

Register bun-plugin-consts with the bun runtime before your code runs using preload feature.

// ./preload/dev.ts

import { plugin } from "bun";
import constsPlugin from "bun-plugin-consts";
//
import consts from "../consts.ts";

plugin(constsPlugin(consts));
0.1.1

11 months ago

0.1.0

11 months ago