{"id":32429382,"url":"https://github.com/mellowco/unplugin-attributify-to-class","last_synced_at":"2025-10-25T20:52:25.319Z","repository":{"id":54632223,"uuid":"522239719","full_name":"MellowCo/unplugin-attributify-to-class","owner":"MellowCo","description":"css attributify mode to class, support use in vite, rollup, webpack","archived":false,"fork":false,"pushed_at":"2023-11-14T13:15:56.000Z","size":2311,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-20T18:34:04.941Z","etag":null,"topics":["attributify","unplugin","vite","webpack"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/unplugin-attributify-to-class","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MellowCo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-08-07T14:45:40.000Z","updated_at":"2025-10-09T09:07:33.000Z","dependencies_parsed_at":"2023-11-14T14:26:33.260Z","dependency_job_id":"30bb81c8-0b46-4691-9293-35da9306fcee","html_url":"https://github.com/MellowCo/unplugin-attributify-to-class","commit_stats":{"total_commits":107,"total_committers":2,"mean_commits":53.5,"dds":"0.11214953271028039","last_synced_commit":"a047d0d1e1fcb8fb7862134d599cecf104757d85"},"previous_names":["mellowco/unplugin-unocss-attributify-wechat"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/MellowCo/unplugin-attributify-to-class","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Funplugin-attributify-to-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Funplugin-attributify-to-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Funplugin-attributify-to-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Funplugin-attributify-to-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MellowCo","download_url":"https://codeload.github.com/MellowCo/unplugin-attributify-to-class/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MellowCo%2Funplugin-attributify-to-class/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281019446,"owners_count":26430647,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attributify","unplugin","vite","webpack"],"created_at":"2025-10-25T20:52:05.611Z","updated_at":"2025-10-25T20:52:25.311Z","avatar_url":"https://github.com/MellowCo.png","language":"TypeScript","readme":"\u003cH1 align='center'\u003e\nunplugin-attributify-to-class\n\u003c/H1\u003e\n\n\u003cp align='center'\u003e\n\u003cb\u003eEnglish\u003c/b\u003e | \u003ca href=\"https://github.com/MellowCo/unplugin-attributify-to-class/blob/master/README.zh-CN.md\"\u003e简体中文\u003c/a\u003e\n\u003c/p\u003e\n\n[![Version](https://img.shields.io/npm/v/unplugin-attributify-to-class.svg?style=flat-square\u0026logo=npm) \n![Downloads](https://img.shields.io/npm/dm/unplugin-attributify-to-class.svg?style=flat-square\u0026logo=npm)](https://www.npmjs.com/package/unplugin-attributify-to-class)\n\n\ncollect and add atomized css [attributify mode](https://github.com/unocss/unocss/tree/main/packages/preset-attributify#attributify-mode) to class , support the use of attributify mode in miniprogram\n\nto fit the functional semantics，`unplugin-unocss-attributify-wechat` rename to `unplugin-attributify-to-class`\n\n\n---\n\n## Why use it\n\nuse `@unocss/preset-attributify` \n```html\n\u003cbutton\n  bg=\"blue-400\"\u003e\n  button\n\u003c/button\u003e\n```\n\ngenerated css\n\n\n```css\n[bg~=\"blue-400\"] {\n  --un-bg-opacity: 1;\n  background-color: rgba(96,165,250,var(--un-bg-opacity));\n}\n```\n\nminiprogram does not support property selectors [bg~=\"blue-400\"] ，[wechat documents](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E7%BB%84%E4%BB%B6%E6%A0%B7%E5%BC%8F)   \n\n---\n\nuse this plugin\n\n```html\n\u003cbutton\n  bg=\"blue-400\"\u003e\n  button\n\u003c/button\u003e\n```\ntransform\n\n```html\n\u003cbutton\n  bg=\"blue-400\"\n  class=\"bg-blue-400\"\u003e\n  button\n\u003c/button\u003e\n```\n\n---\n\n## Installation\n```shell\nnpm i -D unplugin-attributify-to-class\n```\n\n\n\u003cdetails\u003e\n\u003csummary\u003evite\u003c/summary\u003e\u003cbr\u003e\n\n```ts\nimport { defineConfig } from 'vite'\nimport { attributifyToClass, defaultAttributes, defaultIgnoreNonValuedAttributes } from 'unplugin-attributify-to-class/vite'\n\nexport default defineConfig({\n  plugins: [\n    // https://github.com/MellowCo/unplugin-attributify-to-class\n    attributifyToClass(),\n  ],\n})\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\n\n\u003cdetails\u003e\n\u003csummary\u003ewebpack\u003c/summary\u003e\u003cbr\u003e\n\n\n```js\nconst { defaultAttributes, defaultIgnoreNonValuedAttributes, attributifyToClass } = require('unplugin-attributify-to-class/webpack')\n\nmodule.exports = {\n  configureWebpack: {\n    plugins: [\n      // https://github.com/MellowCo/unplugin-attributify-to-class\n      attributifyToClass(),\n    ],\n  },\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\n## Usage\n\n### Options\n```ts\nexport interface Options {\n\n  /**\n   * @default 'un-'\n   */\n  prefix?: string\n\n  /**\n   * Only match for prefixed attributes\n   * @default false\n   */\n  prefixedOnly?: boolean\n\n  /**\n   * A list of attributes to transform class\n   * @default ['bg', 'flex', 'grid', 'border', 'text', 'font', 'class', 'className', 'p', 'm', 'animate']\n   */\n  attributes?: string[]\n\n  /**\n   * A list of non-valued attributes to be ignored from extracting\n   * @default ['class']\n   */\n  ignoreNonValuedAttributes?: string[]\n\n  /**\n   * Support matching non-valued attributes\n   *\n   * For example\n   * ```html\n   * \u003cdiv mt-2 /\u003e\n   * ```\n   *\n   * @default true\n   */\n  nonValuedAttribute?: boolean\n\n  /**\n   * Transform escape char like [ # $ . ,\n   * @default true\n   */\n  transformEscape?: boolean\n\n  /**\n   * Custom transform Rules for escape char\n   * @default https://github.com/MellowCo/unplugin-transform-class#options\n   */\n  transformRules?: Record\u003cstring, string\u003e\n\n  /**\n   * Rules to exclude transforming target\n   * @default [/[\\\\/]node_modules[\\\\/]/, /[\\\\/]\\.git[\\\\/]/]\n   */\n  exclude?: FilterPattern\n\n  /**\n    * Rules to include transforming target\n    * @default [/\\.vue$/,  /\\.vue\\?vue/]\n    */\n  include?: FilterPattern\n\n  /**\n    * Add prefix for class\n    * @default ''\n    */\n  classPrefix?: string\n}\n```\n\n### Attributify Mode\nSee [attributify-mode](https://github.com/unocss/unocss/tree/main/packages/preset-attributify#attributify-mode)   \n```html\n\u003cbutton \n  text=\"sm white\"\n  font=\"mono light\"\n  p=\"y-2 x-4\"\n  my-attr=\"y-1 x-2 sm\"\n\u003e\n  Button\n\u003c/button\u003e\n```\nDefault transfrom attributes list ['bg', 'flex', 'grid', 'border', 'text', 'font', 'class', 'className', 'p', 'm', 'animate'] \n\n```html\n\u003cbutton \n  text=\"sm white\"\n  font=\"mono light\"\n  p=\"y-2 x-4\"\n  my-attr=\"y-1 x-2 sm\"\n  class=\"text-sm text-white font-mono font-light p-y-2 p-x-4\" \n\u003e\n  Button\n\u003c/button\u003e\n```\n\nAdd new `attributes`, like `my-attr`\n\n```ts\nimport { attributifyToClass, defaultAttributes } from 'unplugin-attributify-to-class/vite'\n// import { attributifyToClass, defaultAttributes } from 'unplugin-attributify-to-class/webpack'\n\nattributifyToClass({\n  attributes: [...defaultAttributes, 'my-attr']\n})\n```\n\n```html\n\u003cbutton \n  text=\"sm white\"\n  font=\"mono light\"\n  p=\"y-2 x-4\"\n  my-attr=\"y-1 x-2 sm\"\n  class=\"text-sm text-white font-mono font-light p-y-2 p-x-4 my-attr-y-1 my-attr-x-2 my-attr-sm \"\u003e\n  Button\n\u003c/button\u003e\n```\n\n\n### Prefix Self-referencing\nFor utilities like flex, grid, border, that have the utilities same as the prefix, a special ~ value is provided.\n\n```html\n\u003cbutton class=\"border border-red\"\u003e\n  Button\n\u003c/button\u003e\n```\nCan be written as\n```html\n\u003cbutton border=\"~ red\"\u003e\n  Button\n\u003c/button\u003e\n```\n\n### Valueless Attributify\n```html\n\u003cbutton m-2 rounded text-teal-400 /\u003e\n```\nIt will be add class after transform \n```html\n\u003cbutton \n  m-2 rounded text-teal-400\n  class=\"m-2 rounded text-teal-400\" \n/\u003e\n```\n\nNotice\n* Valueless Attributify default value is `true`\n* Extract all valueless attributes by default，you can use `ignoreNonValuedAttributes`，exclude unnecessary attributes to avoid generating redundant class\n* `ignoreNonValuedAttributes` default value is `['class']`\n\n\n```html\n\u003cbutton m-2 rounded text-teal-400 my-prop is-top/\u003e\n```\nAfter transform ，`my-prop` and  `is-top` will be add to class\n\n```html\n\u003cbutton \n  m-2 rounded text-teal-400 my-prop is-top\n  class=\"m-2 rounded text-teal-400 my-prop is-top\" \n/\u003e\n```\n\nSetting  `ignoreNonValuedAttributes` to ignore `my-prop` `is-top`\n```ts\nimport { attributifyToClass, defaultIgnoreNonValuedAttributes } from 'unplugin-attributify-to-class/vite'\n// import { attributifyToClass, defaultIgnoreNonValuedAttributes } from 'unplugin-attributify-to-class/webpack'\n\nattributifyToClass({\n  // open valueless attributify\n  nonValuedAttribute: true,\n  // ignore non-valued attributes\n  ignoreNonValuedAttributes: [...defaultIgnoreNonValuedAttributes, 'my-prop', 'is-top']\n})\n```\n\n```html\n\u003cbutton \n  m-2 rounded text-teal-400 my-prop is-top\n  class=\"m-2 rounded text-teal-400\" \n/\u003e\n```\n\n### Properties Conflicts\nIf the name of the attributes mode ever conflicts with the elements' or components' properties, you can add `un-` prefix to be specific to attributify mode.  \n\n```html\n\u003ca \n  text=\"red\" \n  bg-red\n  un-text=\"blue\"\n  un-bg-blue\n\u003e\n  This conflicts with links' `text` prop\n\u003c/a\u003e\n```\n\nSetting\n\n```ts\nattributifyToClass({\n  prefix: 'un-',\n  prefixedOnly: true,\n})\n```\n\nTransform\n\n```html\n\u003ca \n  text=\"red\" \n  bg-red\n  un-text=\"blue\"\n  un-bg-blue\n  class=\"text-blue bg-blue\"\n\u003e\n  This conflicts with links' text prop\n\u003c/a\u003e\n```\n\n\n### TransformEscape\n\u003e Because `uniappp vue2` `taro` `webpack plugin`， `bg=\"[#333]\"` compile as `bg-  333`, the style cannot be displayed normally\n\u003e so transform escape char for bg=\"[#333]\", `bg=\"[#333]\" =\u003e bg--fl--w-333-fr`\n\n* Default open，setting with  `transformEscape`\n* You can setting custom rules with `transfromRules`, [default transformRules](https://github.com/MellowCo/unplugin-transform-class)\n\ncustom transfrom rules\n```ts\nconst myRules = {\n  '.': '-dxxx-',\n  '/': '-sxxx-',\n  ':': '-cxxx-',\n  '%': '-pxxx-',\n  '!': '-exxx-',\n  '#': '-wxxx-',\n  '(': '-blxxx-',\n  ')': '-brxxx-',\n  '[': '-flxxx-',\n  ']': '-frxxx-',\n  '$': '-rxxx-',\n}\n\nattributifyToClass({\n  transformEscape: true,\n  transformRules: myRules\n})\n```\n\n### Include exclude\n```ts\nattributifyToClass({\n  exclude: [/[\\\\/]node_modules[\\\\/]/, /[\\\\/]\\.git[\\\\/]/, /[\\\\/]my-folder[\\\\/]/],\n  include: [/\\.vue$/, /\\.vue\\?vue/]\n})\n```\n\n---\n### classPrefix\n\u003e Add prefix for class \n\n```html\n\u003cbutton bg-green bg-red text=\"center left\"\u003e\u003c/button\u003e\n\n\u003cbutton \n  bg-green bg-red \n  text=\"center left\" \n  class=\"bg-green bg-red text-center text-left\"\n\u003e\u003c/button\u003e\n```\n\nSetting classPrefix with `li-`\n\n```ts\nattributifyToClass({\n  nonValuedAttribute: true,\n  classPrefix: 'li-',\n})\n```\nAfter transform , bg-green =\u003e class=\"li-bg-green\"\n```html\n\u003cbutton \n  bg-green bg-red \n  text=\"center left\" \n  class=\"li-bg-green li-bg-red li-text-center li-text-left\"\n\u003e\u003c/button\u003e\n```\n\nrelated links\n* [unocss-preset-weapp](https://github.com/MellowCo/unocss-preset-weapp) - Uthe unocss preset for wechat miniprogram.\n\n---\n### utils\n```ts\nimport { extractorAttributify } from 'unplugin-attributify-to-class/utils'\nconst options = {\n  // ...\n}\n\nconst extractor = extractorAttributify(options)\n\nconst code = 'xxxxx'\nconst newCode = extractor(code)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmellowco%2Funplugin-attributify-to-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmellowco%2Funplugin-attributify-to-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmellowco%2Funplugin-attributify-to-class/lists"}