JavaScript / TypeScript

warning

There will be some upcoming breaking changes (TBD) to the JS plugin in Terrazzo 2.0 stable to support the DTCG Resolver module.

Terrazzo’s JS plugin generates JavaScript, TypeScript, and JSON output from your tokens.

Setup

npm i -D @terrazzo/plugin-js
import { defineConfig } from "@terrazzo/cli";
import js from "@terrazzo/plugin-js";

export default defineConfig({
  plugins: [
    js({
      js: "index.js",
      ts: "index.d.ts",
      json: false, // set to a filename to generate JSON
    }),
  ],
});

Usage

import token from "./tokens/index.js";

token("color.blue.500");

Config

Configure options in terrazzo.config.js:

import { defineConfig } from "@terrazzo/cli";
import js from "@terrazzo/plugin-js";

export default defineConfig({
  plugins: [
    js({
      /* options */
    }),
  ],
});

Options

NameTypeDescription
jsstring | booleanSet to a filename, or false to disable (default: index.js).
tsstring | booleanSet to a filename, or false to disable (default: index.d.ts) Note: this can’t be enabled if js is disabled).
jsonstring | booleanSet to a filename, or false to disable (default: false).