bun-plugin-consts
v0.1.1
Published
Dependency injection for constants using ECMAScript module import syntax.
Downloads
4
Maintainers
Readme
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));