This is how Style Dictionary works under the hood.
Let's take a closer look into each of these steps.
Style Dictionary is a configuration based framework, you tell it what to do in a configuration file. Style Dictionary first parses this configuration to know what to do.
In your config file you define a source
, which is an array of file paths. This tells Style Dictionary where to find your token files. You can have them anywhere and in any folder structure as long as you tell Style Dictionary where to find them.
Style Dictionary takes all the files it found and performs a deep merge. This allows you to split your token files in any way you like, without worrying about accidentally overriding groups of tokens. This gives Style Dictionary a single, complete token object to work from.
For each platform defined in your config, Style Dictionary will do a few steps to get it ready to be consumed on that platform. You don't need to worry about one platform affecting another because everything that happens in a platform is non-destructive
Style Dictionary now traverses over the whole token object and looks for design tokens. It does this by looking for anything with a value
key. When it comes across a design token, it then performs all the transforms defined in your config in order.
After all the tokens have been transformed, it then does another pass over the token object looking for aliases, which look like "{size.font.base.value}"
. When it finds these, it then replaces the reference with the transformed value. As we have a single complete token object, aliases can be in any token file and still work.
Now all the design tokens are ready to be written to a file. Style Dictionary takes the whole transformed and resolved token object and for each file defined in the platform it formats the token object and write the output to a file. Internally, Style Dictionary creates a flat array of all the design tokens it finds in addition to the token object. This is how you can output a flat SCSS variables file.
After Style Dictionary does steps 4-6 for each platform, now you have all your output files that are ready to consume in each platform and codebase.