【问题标题】:Is there a way to overwrite some data from the extended json config file in StyleDictionary?有没有办法从 StyleDictionary 中的扩展 json 配置文件中覆盖一些数据?
【发布时间】:2022-01-06 13:18:24
【问题描述】:

问题很简单:

我有一个 javascript 文件

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

还有一个 json 配置文件

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

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

暂时没找到好办法,唯一好办法就是直接编辑config json文件。

有更好的想法吗?

【问题讨论】:

    标签: javascript json style-dictionary


    【解决方案1】:

    这就是答案,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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 2022-09-23
      • 1970-01-01
      • 2021-08-13
      • 2021-02-02
      • 1970-01-01
      相关资源
      最近更新 更多