@flags-sdk/launchdarkly

中文文档
1.1.1发布于 2026/08/12MITTypeScriptESM + CJS构建来源已验证近 30 天下载 8.1万

LaunchDarkly provider for the Flags SDK

原始使用文档
文档目录5 节
  1. Setup
  2. Provider Instance
  3. Example
  4. Custom Adapter
  5. Documentation

Flags SDK - LaunchDarkly Provider

The LaunchDarkly provider for the Flags SDK contains support for LaunchDarkly's Feature Flags.

Setup

The Statsig provider is available in the @flags-sdk/statsig module. You can install it with

npm i @flags-sdk/launchdarkly

Provider Instance

NOTE: The LaunchDarkly Vercel integration must be installed on your account, as this adapter loads LaunchDarkly from Global Config. The adapter can not be used without Global Config.

Import the default adapter instance ldAdapter from @flags-sdk/launchdarkly:

import { ldAdapter } from "@flags-sdk/launchdarkly";

The default adapter uses the following environment variables to configure itself:

export LAUNCHDARKLY_CLIENT_SIDE_ID="612376f91b8f5713a58777a1"
export LAUNCHDARKLY_PROJECT_SLUG="my-project"
# Provided by the LaunchDarkly Marketplace integration when Global Config is
# enabled for the collection.
export EXPERIMENTATION_CONFIG="https://global-config.vercel.com/ecfg_abdc1234?token=xxx-xxx-xxx"

Using the legacy LaunchDarkly Vercel integration? The default adapter reads the Global Config connection string from EXPERIMENTATION_CONFIG only. If your project provides the connection string as GLOBAL_CONFIG, set EXPERIMENTATION_CONFIG to the same value, or pass it explicitly with createLaunchDarklyAdapter.

Example

import { flag, dedupe } from "flags/next";
import { ldAdapter, type LDContext } from "@flags-sdk/launchdarkly";

const identify = dedupe(async (): Promise<LDContext> => {
  return {
    key: "user_123",
  };
});

export const showBanner = flag<boolean, LDContext>({
  key: "show-banner",
  identify,
  adapter: ldAdapter.variation(),
});

Custom Adapter

Create an adapter by using the createLaunchDarklyAdapter function:

import { createLaunchDarklyAdapter } from "@flags-sdk/launchdarkly";

const adapter = createLaunchDarklyAdapter({
  projectSlug: "my-project",
  clientSideId: "612376f91b8f5713a58777a1",
  // Legacy integrations that provide the connection string as `GLOBAL_CONFIG`
  // can pass it explicitly here.
  globalConfigConnectionString:
    process.env.EXPERIMENTATION_CONFIG ?? process.env.GLOBAL_CONFIG,
});

Documentation

Please check out the LaunchDarkly provider documentation for more information.

版本与发布记录

@flags-sdk/launchdarkly 共发布 23 个版本,首次发布于 2024/12/13;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.1latest2026/08/123 个月前
1.1.02026/08/053 个月前
1.0.02026/07/104 个月前
0.3.42025/11/061 年前
0.3.4-fcec5ecd-20251106144952snapshot2025/11/061 年前
0.3.32025/10/251.1 年前

关于 @flags-sdk/launchdarkly 的常见问题

@flags-sdk/launchdarkly 是什么?

LaunchDarkly provider for the Flags SDK

如何安装 @flags-sdk/launchdarkly?

在项目目录运行 npm install @flags-sdk/launchdarkly,或使用 pnpm add / yarn add / bun add。

@flags-sdk/launchdarkly 支持 TypeScript 吗?

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

@flags-sdk/launchdarkly 支持 ESM 还是 CommonJS?

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

@flags-sdk/launchdarkly 可以商用吗?

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

@flags-sdk/launchdarkly 的下载量有多少?

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

@flags-sdk/launchdarkly 还在维护吗?

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