Skip to main content
Home

Built and signed on GitHub Actions

An esbuild plugin for Deno.env

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (1.2.0)

esbuild-deno-env

JSR codecov GitHub semantic-release: angular standard-readme compliant

An esbuild plugin for Deno.env.

Table of Contents

Install

deno:

deno add @miyauci/esbuild-deno-env

node:

npx jsr add @miyauci/esbuild-deno-env

Usage

The denoEnvPlugin adds a mock Deno.env to the bundle through esbuild inject.

It receives the initial values of the environment variables.

import { denoEnvPlugin } from "@miyauci/esbuild-deno-env";
import { build } from "esbuild";

declare const env: { ENDPOINT: string };

await build({
  stdin: {
    contents: `Deno.env.get("ENDPOINT");`,
  },
  plugins: [denoEnvPlugin(env)],
  bundle: true,
  format: "esm",
});

output:

// deno-env:deno-env:
var DenoEnv = class {
  #env;
  constructor(init = {}) {
    this.#env = new Map(Object.entries(init));
  }
  get(key) {
    return this.#env.get(key);
  }
  set(key, value) {
    this.#env.set(key, value);
  }
  delete(key) {
    this.#env.delete(key);
  }
  has(key) {
    return this.#env.has(key);
  }
  toObject() {
    return Object.fromEntries(this.#env);
  }
};
var env = /* @__PURE__ */ new DenoEnv({ "ENDPOINT": "<ENDPOINT>" });

// <stdin>
console.log(env.get("ENDPOINT"));

API

See jsr doc for all APIs.

Contributing

See contributing.

License

MIT © 2024 Tomoki Miyauchi

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@miyauci/esbuild-deno-env

Import symbol

import * as esbuild_deno_env from "@miyauci/esbuild-deno-env";
or

Import directly with a jsr specifier

import * as esbuild_deno_env from "jsr:@miyauci/esbuild-deno-env";

Add Package

pnpm i jsr:@miyauci/esbuild-deno-env
or (using pnpm 10.8 or older)
pnpm dlx jsr add @miyauci/esbuild-deno-env

Import symbol

import * as esbuild_deno_env from "@miyauci/esbuild-deno-env";

Add Package

yarn add jsr:@miyauci/esbuild-deno-env
or (using Yarn 4.8 or older)
yarn dlx jsr add @miyauci/esbuild-deno-env

Import symbol

import * as esbuild_deno_env from "@miyauci/esbuild-deno-env";

Add Package

vlt install jsr:@miyauci/esbuild-deno-env

Import symbol

import * as esbuild_deno_env from "@miyauci/esbuild-deno-env";

Add Package

npx jsr add @miyauci/esbuild-deno-env

Import symbol

import * as esbuild_deno_env from "@miyauci/esbuild-deno-env";

Add Package

bunx jsr add @miyauci/esbuild-deno-env

Import symbol

import * as esbuild_deno_env from "@miyauci/esbuild-deno-env";