0

问题很简单:

我有一个 javascript 文件

const StyleDictionary = require('style-dictionary').extend('color-config.json');

和一个 json 配置文件

{
  "source": ["tokens/color.json"],
  "platforms": {
    "css": {
      "transforms": ["color/css"],

由于我使用的是特定架构,因此我需要在所有令牌配置 json 的源前面加上一个预路径,所以目前的情况是在我的构建过程中源代码 tokens/color.json不起作用,而是我需要使用例如一些东西像这样/extra/architecture/private/tokens/color.json。但我不想直接在 json 中附加这个预路径,我希望能够通过一个配置参数通过 javascript 添加它。

目前我找不到一个好的方法,唯一的好方法是直接编辑配置 json 文件。

有更好的想法吗?

4

1 回答 1

0

这是答案,extend可以多次返工,并返回样式字典新更新的对象处理程序。

const StyleDictionary = require('style-dictionary').extend('color-config.json');

StyleDictionary.extend({
  source: StyleDictionary?.options?.source
    ? StyleDictionary.options.source.map(
        source => `extra/architecture/private/${source}`
      )
    : [],
  platforms: StyleDictionary.options.platforms,
}).buildAllPlatforms();
于 2022-01-10T08:04:42.997 回答