bun-plugin-dotenvx
Version:
A Bun plugin for a seamless dotenvx experience.
52 lines (50 loc) • 1.38 kB
JavaScript
// @bun
// src/plugin.ts
import process from "process";
import * as dotenvx from "@dotenvx/dotenvx";
function createDotenvxPlugin(options = {}) {
return {
name: "bun-plugin-dotenvx",
async setup(build) {
dotenvx.config({
path: options.path || [".env"],
overload: options.overload,
strict: options.strict,
ignore: options.ignore,
envKeysFile: options.envKeysFile,
...options.quiet && { logLevel: "error" },
...options.verbose && { logLevel: "verbose" },
...options.debug && { logLevel: "debug" },
...options.logLevel && { logLevel: options.logLevel }
});
build.onLoad({ filter: /\.env.*$/ }, async (args) => {
const filePath = args.path;
if (filePath) {
const fileOptions = {
...options,
path: [filePath]
};
dotenvx.config(fileOptions);
}
const exports = process.env;
return {
exports: {
default: exports,
...exports
},
loader: "object"
};
});
}
};
}
var plugin_default = createDotenvxPlugin;
// src/index.ts
import * as dotenvx2 from "@dotenvx/dotenvx";
dotenvx2.config();
await Bun.plugin(createDotenvxPlugin());
var src_default = createDotenvxPlugin;
export {
src_default as default,
createDotenvxPlugin
};