Style Dictionary is a build-system that runs in both NodeJS and browsers (natively), to parse and transform your design tokens to then export them to any platform:
iOS, Android, CSS, JS, HTML, sketch files, style documentation, or anything you can think of.
It’s also forward-compatible with Design Token Community Group spec.
Watch the Demo on Youtube
Experiment in the playground
Installation
If you want to use the CLI, you can install it globally via npm:
Or you can install it like a normal npm dependency. Style Dictionary is a build tool, and you are most likely to use it as a dev dependency:
Creating a New Project
The CLI comes with some starter code to get a new project started easily.
This command will copy over the example files found in the basic example in this repo and then run the style-dictionary build command to generate the build artifacts. You should see something like this output:
Pat yourself on the back, you built your first style dictionary! Take a look at what you built. This should have created a build directory and it should look like this:
README.md
config.json
Directorytokens
Directorycolor
base.json
font.json
Directorysize
font.json
Directorybuild
Directoryandroid
font_dimens.xml
colors.xml
Directorycompose
StyleDictionaryColor.kt
StyleDictionarySize.kt
Directoryscss
_variables.scss
Directoryios
StyleDictionaryColor.h
StyleDictionaryColor.m
StyleDictionarySize.h
StyleDictionarySize.m
Directoryios-swift
StyleDictionary.swift
StyleDictionaryColor.swift
StyleDictionarySize.swift
If you open config.json you will see there are 3 platforms defined: scss, android, ios. Each platform has a transformGroup, buildPath, and files defined. The buildPath and files of the platform should match up to the files what were built. Those files should look like these:
Android
Compose
SCSS
iOS
Pretty nifty! This shows a few things happening:
The build system does a deep merge of all the design token files defined in the source attribute of config.json. This allows you to split up the design token files however you want. There are 2 JSON files with color as the top level key, but they get merged properly.
The build system resolves references to other design tokens. {size.font.medium.value} is resolved properly.
The build system handles references to design token values in other files as well (as you can see in tokens/color/font.json).
Values are transformed specifically for each platform.
Making a change
Now let’s make a change and see how that affects things. Open up tokens/color/base.json and change "#111111" to "#000000". After you make that change, save the file and re-run the build command style-dictionary build. Open up the build files and take a look. Now:
Android
That’s it! There is a lot more you can do with your style dictionary than generating files with color values. Take a look
at some examples or take a deeper dive into package structure, extending, or how the build process works.
Basic Usage
Command Line Interface (CLI)
Call this in the root directory of your project, which must include a configuration file.
You can also use the Style Dictionary build system in node if you want to extend the functionality or use it in another build system like Grunt or Gulp.
The StyleDictionary constructor can also take a configuration object.