Skip to content

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

Instead of a path to a resolver file, pass a ResolverDocument object:

import type { ResolverDocument } from 'dispersa'
import { Dispersa, css } from 'dispersa'
import { colorToHex, nameKebabCase } 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' }],
}
const dispersa = new Dispersa({ resolver })

Do not set buildPath. Omit the file option on outputs. Generated content is available on output.content:

const result = await dispersa.build({
outputs: [
css({
name: 'css',
preset: 'bundle',
selector: ':root',
transforms: [nameKebabCase(), colorToHex()],
}),
],
})
for (const output of result.outputs) {
console.log(output.content) // CSS string
}

Use resolveTokens() to resolve tokens for a single permutation without rendering. Pass the same inline resolver used in the constructor:

const tokens = await dispersa.resolveTokens(resolver, { theme: 'light' })
// Use tokens for validation, transformation, or custom rendering

Use resolveAllPermutations() to get all permutations at once:

const allPermutations = await dispersa.resolveAllPermutations(resolver)
// allPermutations is an array of { tokens, modifierInputs } for each modifier combination

Write unit tests that verify token output without writing files:

const dispersa = new Dispersa({ resolver: testResolver })
const result = await dispersa.build({
outputs: [css({ name: 'css', preset: 'bundle', selector: ':root', transforms: [colorToHex()] })],
})
expect(result.outputs[0].content).toContain('--color-primary: #0066cc')