@dcl/ui-env

中文文档
2.1.0发布于 2026/09/14ISCTypeScriptES Module零依赖构建来源已验证近 30 天下载 6513

This package can be used to generate configurations for different environments for web apps and frontends in general. This is handy for frontends that have a single build that is deployed to different envs (such as rollouts).

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Test
  4. Build
  5. Release

ui-env

This package can be used to generate configurations for different environments for web apps and frontends in general. This is handy for frontends that have a single build that is deployed to different envs (such as rollouts).

Installation

npm i @dcl/ui-env

Usage

You need to create a config instance passing the different variables for all the desired envs.

// config/env/dev|stg|prod.json
{
  "FOO": "bar"
}
// config/index.ts
import { Env, createConfig } from '@dcl/ui-env'
import dev from './env/dev.json'
import stg from './env/stg.json'
import prod from './env/prod.json'

export const config = createConfig({
  [Env.DEVELOPMENT]: dev,
  [Env.STAGING]: stg,
  [Env.PRODUCTION]: prod,
})

And then you can get the values for variables from other parts of your code base

// some-file.ts
import { config } from './config'

const someVar = config.get('FOO') // "bar"

You can pass default values as the second argument

const someVar = config.get('NON_EXISTENT_VAR', 'defaultValue') // "defaultValue"

The config will pick the value from the right environment by checking the top level domain:

  • Env.DEVELOPMENT: If TLD is .io or .zone
  • Env.STAGING: If TLD is .net or .today
  • Env.PRODUCTION: If TLD is .org

You can override this logic by passing a query param env with the values dev, stg or prod. The param name and its value can be either uppercase or lowercase.

For example:

  • https://builder.decentraland.io?env=prod: This will use Env.PRODUCTION
  • http://localhost:3000?env=dev: This will use Env.DEVELOPMENT

If no TLD is found and there is no query param, the default environment will be used, which is Env.PRODUCTION.

If you want to override the default environment you can use the environment var DCL_DEFAULT_ENV, REACT_APP_DCL_DEFAULT_ENV or VITE_DCL_DEFAULT_ENV and set it with the values dev, stg or prod.

This can be useful to configure the local environment or for deployments to other non-decentraland domains such as Vercel's.

For example:

# .env
REACT_APP_DCL_DEFAULT_ENV=dev

Now http://localhost:3000 uses the Env.DEVELOPMENT configuration without having to pass a query param.

Test

npm test

Or with coverage reports

npm run test:coverage

Build

npm run build

Release

To release a new version of this package create a new release via GitHub

版本与发布记录

@dcl/ui-env 共发布 29 个版本,首次发布于 2022/06/03;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.1.0latest2026/09/141 个月前
2.0.1-20260914125642.commit-886d7e8next2026/09/141 个月前
2.0.1-20260605150314.commit-55bf0fe2026/06/055 个月前
2.0.02026/01/0710 个月前
1.5.2-20260106171541.commit-2d28bb62026/01/0710 个月前
1.5.12024/08/052 年前

关于 @dcl/ui-env 的常见问题

@dcl/ui-env 是什么?

This package can be used to generate configurations for different environments for web apps and frontends in general. This is handy for frontends that have a single build that is deployed to different envs (such as rollouts).

如何安装 @dcl/ui-env?

在项目目录运行 npm install @dcl/ui-env,或使用 pnpm add / yarn add / bun add。

@dcl/ui-env 支持 TypeScript 吗?

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

@dcl/ui-env 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dcl/ui-env 可以商用吗?

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

@dcl/ui-env 的下载量有多少?

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

@dcl/ui-env 还在维护吗?

最新版本 2.1.0 发布于 2026/09/14(1 个月前);至今共发布 29 个版本,其中过去 12 个月发布了 5 个;首次发布于 2022/06/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。