In-Memory Mode
When to Use In-Memory Mode
Section titled “When to Use In-Memory Mode”- Build tools that process tokens from a database or API
- API endpoints that generate token output on request
- Unit tests that verify token output
- Serverless functions with read-only or ephemeral filesystems
Pass a ResolverDocument Directly
Section titled “Pass a ResolverDocument Directly”Instead of a path to a resolver file, pass a ResolverDocument object:
import type { ResolverDocument } from 'dispersa'import { build, resolveTokens, resolveAllPermutations, css } from 'dispersa'import { colorToHex } from 'dispersa/transforms'
const resolver: ResolverDocument = { version: '2025.10', sets: { base: { sources: [ { color: { primary: { $type: 'color', $value: { colorSpace: 'srgb', components: [0, 0.4, 0.8] }, }, }, }, ], }, }, resolutionOrder: [{ $ref: '#/sets/base' }],}Omit buildPath — Output Stays in Memory
Section titled “Omit buildPath — Output Stays in Memory”Do not set buildPath. Omit the file option on outputs. Generated content is available on output.content:
const result = await build({ resolver, outputs: [ css({ name: 'css', preset: 'bundle', selector: ':root', transforms: [colorToHex()], }), ],})
for (const output of result.outputs) { console.log(output.content) // CSS string}Token Resolution Without Rendering
Section titled “Token Resolution Without Rendering”Use resolveTokens() to resolve tokens for a single permutation without rendering:
const tokens = await resolveTokens(resolver, { theme: 'light' })// Use tokens for validation, transformation, or custom renderingUse resolveAllPermutations() to get all permutations at once:
const allPermutations = await resolveAllPermutations(resolver)// allPermutations is an array of { tokens, modifierInputs } for each modifier combinationTesting Example
Section titled “Testing Example”Write unit tests that verify token output without writing files:
const result = await build({ resolver: testResolver, outputs: [css({ name: 'css', preset: 'bundle', selector: ':root', transforms: [colorToHex()] })],})expect(result.outputs[0].content).toContain('--color-primary: #0066cc') TypeScript Type Generation Generate TypeScript declaration files from your resolved tokens for type-safe token access.