$npx -y skills add dylantarre/design-system-skills --skill style-dictionaryTransforms design tokens into platform-specific formats (CSS, SCSS, iOS Swift, Android XML). Use when setting up multi-platform token pipelines, creating build processes, or managing cross-platform design systems.
| 1 | # Style Dictionary |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Set up Style Dictionary to transform design tokens into platform-specific formats. The industry standard for design systems that need to output to web, iOS, Android, and other platforms from a single token source. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Setting up a new design system with multi-platform needs |
| 10 | - Converting Figma tokens to code |
| 11 | - Generating CSS, SCSS, iOS Swift, Android XML from one source |
| 12 | - Adding custom token transforms or formats |
| 13 | - Integrating tokens into a build pipeline |
| 14 | |
| 15 | ## Quick Reference: Core Concepts |
| 16 | |
| 17 | | Concept | Purpose | Example | |
| 18 | |---------|---------|---------| |
| 19 | | Token | Design value with metadata | `{ "value": "#3b82f6", "type": "color" }` | |
| 20 | | Transform | Converts token values | `color/hex` → `color/rgb` | |
| 21 | | Format | Outputs to file type | CSS variables, Swift, XML | |
| 22 | | Platform | Target environment | web, ios, android | |
| 23 | |
| 24 | ## The Process |
| 25 | |
| 26 | 1. **Assess token sources**: Where are tokens defined? (Figma, JSON, YAML) |
| 27 | 2. **Identify platforms**: Which platforms need tokens? |
| 28 | 3. **Set up config**: Create `style-dictionary.config.js` |
| 29 | 4. **Define transforms**: Add any custom value transformations |
| 30 | 5. **Build**: Run `style-dictionary build` |
| 31 | |
| 32 | ### Implementation Checklist |
| 33 | |
| 34 | Copy this checklist when setting up Style Dictionary: |
| 35 | |
| 36 | ``` |
| 37 | Style Dictionary Setup: |
| 38 | - [ ] Install: `npm install style-dictionary` |
| 39 | - [ ] Create tokens/ directory with source JSON files |
| 40 | - [ ] Create style-dictionary.config.js with source paths and platform outputs |
| 41 | - [ ] Add build script to package.json: `"tokens:build": "style-dictionary build"` |
| 42 | - [ ] Run build and verify output files are generated correctly |
| 43 | ``` |
| 44 | |
| 45 | --- |
| 46 | |
| 47 | ## Project Setup |
| 48 | |
| 49 | ### Installation |
| 50 | |
| 51 | ```bash |
| 52 | npm install style-dictionary |
| 53 | # or |
| 54 | yarn add style-dictionary |
| 55 | ``` |
| 56 | |
| 57 | ### Directory Structure |
| 58 | |
| 59 | ``` |
| 60 | tokens/ |
| 61 | ├── base/ |
| 62 | │ ├── colors.json |
| 63 | │ ├── spacing.json |
| 64 | │ └── typography.json |
| 65 | ├── semantic/ |
| 66 | │ ├── colors.json |
| 67 | │ └── components.json |
| 68 | └── themes/ |
| 69 | ├── light.json |
| 70 | └── dark.json |
| 71 | |
| 72 | build/ # Generated output |
| 73 | ├── css/ |
| 74 | │ └── variables.css |
| 75 | ├── ios/ |
| 76 | │ └── StyleDictionary.swift |
| 77 | └── android/ |
| 78 | └── colors.xml |
| 79 | |
| 80 | style-dictionary.config.js |
| 81 | ``` |
| 82 | |
| 83 | --- |
| 84 | |
| 85 | ## Configuration |
| 86 | |
| 87 | ### Basic Config |
| 88 | |
| 89 | ```js |
| 90 | // style-dictionary.config.js |
| 91 | module.exports = { |
| 92 | source: ['tokens/**/*.json'], |
| 93 | platforms: { |
| 94 | css: { |
| 95 | transformGroup: 'css', |
| 96 | buildPath: 'build/css/', |
| 97 | files: [ |
| 98 | { |
| 99 | destination: 'variables.css', |
| 100 | format: 'css/variables', |
| 101 | }, |
| 102 | ], |
| 103 | }, |
| 104 | }, |
| 105 | }; |
| 106 | ``` |
| 107 | |
| 108 | ### Multi-Platform Config |
| 109 | |
| 110 | ```js |
| 111 | // style-dictionary.config.js |
| 112 | module.exports = { |
| 113 | source: ['tokens/**/*.json'], |
| 114 | |
| 115 | platforms: { |
| 116 | // Web - CSS Custom Properties |
| 117 | css: { |
| 118 | transformGroup: 'css', |
| 119 | buildPath: 'build/css/', |
| 120 | files: [ |
| 121 | { |
| 122 | destination: 'variables.css', |
| 123 | format: 'css/variables', |
| 124 | options: { |
| 125 | outputReferences: true, // Keep token references |
| 126 | }, |
| 127 | }, |
| 128 | ], |
| 129 | }, |
| 130 | |
| 131 | // Web - SCSS Variables |
| 132 | scss: { |
| 133 | transformGroup: 'scss', |
| 134 | buildPath: 'build/scss/', |
| 135 | files: [ |
| 136 | { |
| 137 | destination: '_variables.scss', |
| 138 | format: 'scss/variables', |
| 139 | }, |
| 140 | ], |
| 141 | }, |
| 142 | |
| 143 | // Web - JavaScript/TypeScript |
| 144 | js: { |
| 145 | transformGroup: 'js', |
| 146 | buildPath: 'build/js/', |
| 147 | files: [ |
| 148 | { |
| 149 | destination: 'tokens.js', |
| 150 | format: 'javascript/es6', |
| 151 | }, |
| 152 | { |
| 153 | destination: 'tokens.d.ts', |
| 154 | format: 'typescript/es6-declarations', |
| 155 | }, |
| 156 | ], |
| 157 | }, |
| 158 | |
| 159 | // iOS - Swift |
| 160 | ios: { |
| 161 | transformGroup: 'ios-swift', |
| 162 | buildPath: 'build/ios/', |
| 163 | files: [ |
| 164 | { |
| 165 | destination: 'StyleDictionary.swift', |
| 166 | format: 'ios-swift/class.swift', |
| 167 | className: 'StyleDictionary', |
| 168 | }, |
| 169 | ], |
| 170 | }, |
| 171 | |
| 172 | // Android - XML Resources |
| 173 | android: { |
| 174 | transformGroup: 'android', |
| 175 | buildPath: 'build/android/', |
| 176 | files: [ |
| 177 | { |
| 178 | destination: 'colors.xml', |
| 179 | format: 'android/colors', |
| 180 | filter: { type: 'color' }, |
| 181 | }, |
| 182 | { |
| 183 | destination: 'dimens.xml', |
| 184 | format: 'android/dimens', |
| 185 | filter: { type: 'dimension' }, |
| 186 | }, |
| 187 | ], |
| 188 | }, |
| 189 | }, |
| 190 | }; |
| 191 | ``` |
| 192 | |
| 193 | --- |
| 194 | |
| 195 | ## Token Format |
| 196 | |
| 197 | ### Design Tokens Community Group (DTCG) Format |
| 198 | |
| 199 | ```json |
| 200 | { |
| 201 | "color": { |
| 202 | "primary": { |
| 203 | "$value": "#3b82f6", |
| 204 | "$type": "color", |
| 205 | "$description": "Primary brand color" |
| 206 | }, |
| 207 | "secondary": { |
| 208 | "$value": "#64748b", |
| 209 | "$type": "color" |
| 210 | } |
| 211 | }, |
| 212 | "spacing": { |
| 213 | "sm": { |
| 214 | "$value": "8px", |
| 215 | "$type": "dimension" |
| 216 | }, |
| 217 | "md": { |
| 218 | "$value": "16px", |
| 219 | "$type": "dimension" |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | ``` |
| 224 | |
| 225 | ### Style Dictionary Classic Format |
| 226 | |
| 227 | ```json |
| 228 | { |
| 229 | "color |