Skip to content

Custom transform not working with hooks in Style Dictionary 4 #1426

Closed
@Leejha

Description

I'm trying to implement a custom transform using hooks in Style Dictionary 4, but the transform is not being executed. Here's my configuration:

export default {
  source: [flattenedTokensPath],
  hooks: {
    transforms: {
      CssCustomPrefix: {
        transform: (token) => {
          console.log("test");  // This is never logged
          return token;
        },
      },
    },
  },
  platforms: {
    css: {
      transforms: ["CssCustomPrefix"],
      buildPath: "src/css/",
      files: [
        {
          destination: "color.css",
          format: formats.cssVariables,
          filter: {
            type: "color",
          },
        },
      ],
    }
  }
};

I'm running the build with:
pnpm exec style-dictionary build --config src/style-dictionary/transform-token.js

I also tried using transform groups like this:

export default {
  hooks: {
    transformGroups: {
      temp: ["CssCustomPrefix"],
    },
    transforms: {
      "CssCustomPrefix": {
        transform: (token) => {
          console.log("test");  // This is never logged
          return token;
        },
    },
  },
  platforms: {
    css: {
      transformGroup: [transformGroups.css, "temp"],
      // ... rest of the config
    }
  }
};

But neither approach seems to work - the transform is never executed (no console.log output).

Expected behavior:

The custom transform should be executed
console.log in the transform should be visible in the output

Actual behavior:

The transform appears to be ignored
No console.log output is visible
The build completes successfully but without applying the custom transform

Environment:

Style Dictionary version: 4.3.0
Node.js version: 20.16.0
Package manager: pnpm

Any help or guidance would be appreciated!

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions