Client Configuration
@layerfig/config/client exports a ConfigBuilder that is safe to bundle for the browser. It accepts a smaller set of options than the server one, because there is no filesystem to read from:
| Option | Client | Default |
|---|---|---|
validate |
✅ required | — |
runtimeEnv |
✅ | import.meta.env |
slotPrefix |
✅ | "$" |
absoluteConfigFolderPath |
❌ not available | — |
parser |
❌ not available | — |
The accepted sources are narrower too: the client builder takes ObjectSource and EnvironmentVariableSource only. Passing a FileSource throws Invalid source. Client ConfigBuilder only Accepts ObjectSource or EnvironmentVariableSource.
options.validate
Section titled “options.validate”The ConfigBuilder constructor requires a validate function. This function receives two arguments: the final merged configuration and a Zod mini instance (v4). It must return the validated configuration.
You can also use other validation libraries. Return the result of the schema validation from the validate function, and the config object will be typed accordingly:
options.runtimeEnv
Section titled “options.runtimeEnv”Default:
import.meta.env
The object slots are resolved against. On the client this is almost always import.meta.env, which is what bundlers like Vite replace at build time with the subset of variables your framework exposes to the browser.
Pass it explicitly. The default is read once when the module is first evaluated, and some bundlers only substitute import.meta.env where it appears literally in your source — naming it in your own file is the reliable form.
Any plain object works too, which is what makes client configs testable:
options.slotPrefix
Section titled “options.slotPrefix”Default:
"$"
A string that identifies placeholders to be replaced with environment variables.
By default, Layerfig looks for placeholders prefixed with $. You can customize this prefix to avoid conflicts or to match a team’s convention.
For example, to use a double underscore (__) as the prefix:
Layerfig will now look for placeholders like __{PUBLIC_APP_VERSION}.
Assuming the PUBLIC_APP_VERSION environment variable is set, the resolved configuration will be: