@vercel/prepare-flags-definitions
v0.2.1
Published
A build-time utility for [Vercel Flags](https://vercel.com/docs/flags/vercel-flags) that fetches flag definitions and bundles them into a synthetic `@vercel/flags-definitions` package inside `node_modules`. This allows `@vercel/flags-core` to access flag
Readme
@vercel/prepare-flags-definitions
A build-time utility for Vercel Flags that fetches flag definitions and bundles them into a synthetic @vercel/flags-definitions package inside node_modules. This allows @vercel/flags-core to access flag definitions instantly at runtime, even when the network is unavailable.
This package is used by the Vercel CLI and other build tools. You typically do not need to install it directly.
Installation
npm i @vercel/prepare-flags-definitionsUsage
import { prepareFlagsDefinitions } from '@vercel/prepare-flags-definitions';
const result = await prepareFlagsDefinitions({
cwd: process.cwd(),
env: process.env,
userAgentSuffix: 'my-build-tool/1.0.0',
});
if (result.created) {
console.log(`Bundled definitions for ${result.sdkKeysCount} SDK keys`);
} else {
console.log(`No definitions created: ${result.reason}`);
}How It Works
- Scans environment variables for SDK keys (matching
vf_server_*orvf_client_*) - Fetches flag definitions from
flags.vercel.comfor each key - Generates an optimized JavaScript module with deduplication and lazy parsing
- Writes the module to
node_modules/@vercel/flags-definitions/
At runtime, @vercel/flags-core imports this module as a fallback when streaming or polling is unavailable.
