@dotenv-run/esbuild

中文文档
1.5.3发布于 2026/08/13ISCTypeScriptESM + CJS近 30 天下载 7.1万

Run your scripts with dotenv variables

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Using define (recommended)
  4. Using esbuild plugin

@dotenv-run/esbuild

  • ✅ Load environment variables from the command line API_BASE=/v1/ node esbuild.mjs
  • ✅ Load environment variables from .env files
  • ✅ Expand environment variables API_URL=$API_BASE/users
  • ✅ Define environment variables for a specific environment (e.g. .env.production)
  • ✅ Load priorities of .env.* files (e.g. .env.production > .env)
  • ✅ Hierarchical cascading configuration in monorepo projects (Nx, Turbo, etc.) apps/next-app/.env > apps/.env > .env

Install

npm add @dotenv-run/esbuild --save-dev

Usage

import { build } from "esbuild";
import { env } from "@dotenv-run/esbuild";

const { full } = env({
  prefix: "MY_",
  verbose: false,
  files: [".env"],
});

const results = await build({
  bundle: true,
  write: false,
  entryPoints: [`test/app.js`],
  define: full,
});

Using esbuild plugin

import { build } from "esbuild";
import { dotenvRun } from "@dotenv-run/esbuild";

await build({
  write: false,
  bundle: true,
  entryPoints: [`test/app.js`],
  plugins: [
    dotenvRun({
      verbose: true,
      root: "../../",
      prefix: "^API",
    }),
  ],
});

版本与发布记录

@dotenv-run/esbuild 共发布 17 个版本,首次发布于 2023/10/26;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.5.3latest2026/08/133 个月前
1.5.22026/04/226 个月前
1.5.12025/06/291.4 年前
1.5.02024/11/212 年前
1.4.22024/10/132 年前
1.4.02024/05/292 年前

关于 @dotenv-run/esbuild 的常见问题

@dotenv-run/esbuild 是什么?

Run your scripts with dotenv variables

如何安装 @dotenv-run/esbuild?

在项目目录运行 npm install @dotenv-run/esbuild,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:esbuild(>=0.21.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dotenv-run/esbuild 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dotenv-run/esbuild 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dotenv-run/esbuild 可以商用吗?

@dotenv-run/esbuild 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dotenv-run/esbuild 的下载量有多少?

根据 npm 官方下载统计,@dotenv-run/esbuild 在 2026/10/13 – 2026/11/11 这 30 天内被下载 70,989 次,日均约 2,366 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dotenv-run/esbuild 还在维护吗?

最新版本 1.5.3 发布于 2026/08/13(3 个月前);至今共发布 17 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/10/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。