amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.87k stars 543 forks source link

DTCG format does not support outputReferences? #1109

Closed IanVS closed 6 months ago

IanVS commented 7 months ago

I'm experimenting with setting up style-dictionary, so my apologies if this is a config error. I'm using the DTCG format, and trying to preserve references in the generated css. But, it seems that the reference is not kept.

See this reproduction to see an example:

https://stackblitz.com/edit/stackblitz-starters-3dyujd?file=variables.css&view=editor

Token file:

{
  "color": {
    "$type": "color",
    "base": {
      "gray": {
        "__default": {"$value": "{color.base.gray.50.$value}"},
        "10" : { "$value": "#16191d" },
        "15": { "$value": "#21252c" },
        "20"  : { "$value": "#2b323b" },
        "30"  : { "$value": "#414b58" },
        "40"  : { "$value": "#576475" },
        "50"  : { "$value": "#6c7d93" }
      }
    }
  }
}

config:

{
  "source": ["tokens/**/*.json"],
  "platforms": {
    "css": {
      "transformGroup": "css",
      "files": [
        {
          "format": "css/variables",
          "destination": "variables.css",
          "options":{
            "outputReferences": true
          }
        }
      ]
    }
  }
}

result:

:root {
  --color-base-gray-default: #6c7d93;
  --color-base-gray-50: #6c7d93;
  --color-base-gray-40: #576475;
  --color-base-gray-30: #414b58;
  --color-base-gray-20: #2b323b;
  --color-base-gray-15: #21252c;
  --color-base-gray-10: #16191d;
}
jorenbroekema commented 6 months ago

This is probably an oversight, something we didn't test for when adding DTCG support. Will look into it!

jorenbroekema commented 6 months ago

Fixed in prerelease.19