[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71345":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},71345,"prettier-plugin-tailwindcss","tailwindlabs\u002Fprettier-plugin-tailwindcss","tailwindlabs","A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order.","",null,"TypeScript",7086,179,14,7,0,11,63.87,"MIT License",false,"main",true,[],"2026-06-12 04:01:00","\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Ftailwindlabs\u002Fprettier-plugin-tailwindcss\u002Fmain\u002F.github\u002Fbanner.jpg\" alt=\"prettier-plugin-tailwindcss\" \u002F>\n\nA [Prettier v3+](https:\u002F\u002Fprettier.io\u002F) plugin for Tailwind CSS v3.0+ that automatically sorts classes based on [our recommended class order](https:\u002F\u002Ftailwindcss.com\u002Fblog\u002Fautomatic-class-sorting-with-prettier#how-classes-are-sorted).\n\n## Installation\n\nTo get started, install `prettier-plugin-tailwindcss` as a dev-dependency:\n\n```sh\nnpm install -D prettier prettier-plugin-tailwindcss\n```\n\nThen add the plugin to your [Prettier configuration](https:\u002F\u002Fprettier.io\u002Fdocs\u002Fen\u002Fconfiguration.html):\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-tailwindcss\"]\n}\n```\n\nWhen using a JavaScript config, you can import the types for IntelliSense:\n\n```js\n\u002F\u002F prettier.config.js\n\n\u002F** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} *\u002F\nexport default {\n  plugins: [\"prettier-plugin-tailwindcss\"],\n}\n```\n\n## Upgrading to v0.5.x\n\nAs of v0.5.x, this plugin now requires Prettier v3 and is ESM-only. This means it cannot be loaded via `require()`. For more information see our [upgrade guide](https:\u002F\u002Fgithub.com\u002Ftailwindlabs\u002Fprettier-plugin-tailwindcss\u002Fissues\u002F207#issuecomment-1698071122).\n\n## Options\n\n### Specifying your Tailwind stylesheet path (Tailwind CSS v4+)\n\nWhen using Tailwind CSS v4 you must specify your CSS file entry point, which includes your theme, custom utilities, and other Tailwind configuration options. To do this, use the `tailwindStylesheet` option in your Prettier configuration.\n\nNote that paths are resolved relative to the Prettier configuration file.\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindStylesheet\": \".\u002Fresources\u002Fcss\u002Fapp.css\"\n}\n```\n\n### Specifying your Tailwind JavaScript config path (Tailwind CSS v3)\n\nTo ensure that the class sorting takes into consideration any of your project's Tailwind customizations, it needs access to your [Tailwind configuration file](https:\u002F\u002Ftailwindcss.com\u002Fdocs\u002Fconfiguration) (`tailwind.config.js`).\n\nBy default the plugin will look for this file in the same directory as your Prettier configuration file. However, if your Tailwind configuration is somewhere else, you can specify this using the `tailwindConfig` option in your Prettier configuration.\n\nNote that paths are resolved relative to the Prettier configuration file.\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindConfig\": \".\u002Fstyles\u002Ftailwind.config.js\"\n}\n```\n\nIf a local configuration file cannot be found the plugin will fallback to the default Tailwind configuration.\n\n## Sorting non-standard attributes\n\nBy default this plugin sorts classes in the `class` attribute, any framework-specific equivalents like `className`, `:class`, `[ngClass]`, and any Tailwind `@apply` directives.\n\nYou can sort additional attributes using the `tailwindAttributes` option, which takes an array of attribute names:\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindAttributes\": [\"myClassList\"]\n}\n```\n\nWith this configuration, any classes found in the `myClassList` attribute will be sorted:\n\n```jsx\nfunction MyButton({ children }) {\n  return (\n    \u003Cbutton myClassList=\"rounded bg-blue-500 px-4 py-2 text-base text-white\">\n      {children}\n    \u003C\u002Fbutton>\n  );\n}\n```\n\n### Using regex patterns\n\nYou can also use regular expressions to match multiple attributes. Patterns should be enclosed in forward slashes. Note that JS regex literals are not supported with Prettier:\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindAttributes\": [\"myClassList\", \"\u002Fdata-.*\u002F\"]\n}\n```\n\nThis example will sort classes in the `myClassList` attribute as well as any attribute starting with `data-`:\n\n```jsx\nfunction MyButton({ children }) {\n  return (\n    \u003Cbutton\n      myClassList=\"rounded bg-blue-500 px-4 py-2 text-base text-white\"\n      data-theme=\"dark:bg-gray-800 bg-white\"\n      data-classes=\"flex items-center\"\n    >\n      {children}\n    \u003C\u002Fbutton>\n  );\n}\n```\n\n## Sorting classes in function calls\n\nIn addition to sorting classes in attributes, you can also sort classes in strings provided to function calls. This is useful when working with libraries like [clsx](https:\u002F\u002Fgithub.com\u002Flukeed\u002Fclsx) or [cva](https:\u002F\u002Fcva.style\u002F).\n\nYou can sort classes in function calls using the `tailwindFunctions` option, which takes a list of function names:\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindFunctions\": [\"clsx\"]\n}\n```\n\nWith this configuration, any classes in `clsx()` function calls will be sorted:\n\n```jsx\nimport clsx from 'clsx'\n\nfunction MyButton({ isHovering, children }) {\n  let classes = clsx(\n    'rounded bg-blue-500 px-4 py-2 text-base text-white',\n    {\n      'bg-blue-700 text-gray-100': isHovering,\n    },\n  )\n\n  return (\n    \u003Cbutton className={classes}>\n      {children}\n    \u003C\u002Fbutton>\n  )\n}\n```\n\n## Sorting classes in template literals\n\nThis plugin also enables sorting of classes in tagged template literals.\n\nYou can sort classes in template literals using the `tailwindFunctions` option, which takes a list of function names:\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindFunctions\": [\"tw\"],\n}\n```\n\nWith this configuration, any classes in template literals tagged with `tw` will automatically be sorted:\n\n```jsx\nimport { View, Text } from 'react-native'\nimport tw from 'twrnc'\n\nfunction MyScreen() {\n  return (\n    \u003CView style={tw`bg-white p-4 dark:bg-black`}>\n      \u003CText style={tw`text-md text-black dark:text-white`}>Hello World\u003C\u002FText>\n    \u003C\u002FView>\n  )\n}\n```\n\nThis feature can be used with third-party libraries like `twrnc` or you can create your own tagged template by defining this \"identity\" function:\n\n```js\nconst tw = (strings, ...values) => String.raw({ raw: strings }, ...values)\n```\n\nOnce added, tag your strings with the function and the plugin will sort them:\n\n```js\nconst mySortedClasses = tw`bg-white p-4 dark:bg-black`\n```\n\n## Public API\n\nIf you want to use the Tailwind class sorting logic outside of Prettier, import from the\n`sorter` entrypoint:\n\n```js\nimport { createSorter } from 'prettier-plugin-tailwindcss\u002Fsorter'\n\nlet sorter = await createSorter({\n  base: '\u002Fpath\u002Fto\u002Fproject',\n  stylesheetPath: '.\u002Fapp.css',\n})\n\n\u002F\u002F Sort HTML class attributes (space-separated strings)\nlet sorted = sorter.sortClassAttributes([\n  'sm:bg-tomato bg-red-500',\n  'p-4 m-2'\n])\n\u002F\u002F Returns: ['bg-red-500 sm:bg-tomato', 'm-2 p-4']\n\n\u002F\u002F Sort class lists (arrays of class names)\nlet sortedLists = sorter.sortClassLists([\n  ['sm:bg-tomato', 'bg-red-500'],\n  ['p-4', 'm-2']\n])\n\u002F\u002F Returns: [['bg-red-500', 'sm:bg-tomato'], ['m-2', 'p-4']]\n```\n\n### API Options\n\nThe `createSorter` function accepts the following options:\n\n- **`base`** (optional): The directory used to resolve relative file paths. Defaults to the current working directory.\n- **`filepath`** (optional): The path to the file being formatted. When provided, Tailwind CSS is resolved relative to this path.\n- **`configPath`** (optional): Path to the Tailwind CSS config file (v3). Paths are resolved relative to `base`.\n- **`stylesheetPath`** (optional): Path to the CSS stylesheet used by Tailwind CSS (v4+). Paths are resolved relative to `base`.\n- **`preserveWhitespace`** (optional): Whether to preserve whitespace around classes. Default: `false`.\n- **`preserveDuplicates`** (optional): Whether to preserve duplicate classes. Default: `false`.\n\n### Sorter Methods\n\nThe sorter object returned by `createSorter` has two methods:\n\n- **`sortClassAttributes(classes: string[]): string[]`**\n  Sorts one or more HTML class attributes. Each element should be a space-separated string of class names (like the value of an HTML `class` attribute).\n\n- **`sortClassLists(classes: string[][]): (string | null)[][]`**\n  Sorts one or more class lists. Each element should be an array of individual class names. When removing duplicates (default behavior), duplicate classes are replaced with `null` in the output.\n\n### Using regex patterns\n\nLike the `tailwindAttributes` option, the `tailwindFunctions` option also supports regular expressions to match multiple function names. Patterns should be enclosed in forward slashes. Note that JS regex literals are not supported with Prettier.\n\n## Preserving whitespace\n\nThis plugin automatically removes unnecessary whitespace between classes to ensure consistent formatting. If you prefer to preserve whitespace, you can use the `tailwindPreserveWhitespace` option:\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindPreserveWhitespace\": true,\n}\n```\n\nWith this configuration, any whitespace surrounding classes will be preserved:\n\n```jsx\nimport clsx from 'clsx'\n\nfunction MyButton({ isHovering, children }) {\n  return (\n    \u003Cbutton className=\" rounded  bg-blue-500 px-4  py-2     text-base text-white \">\n      {children}\n    \u003C\u002Fbutton>\n  )\n}\n```\n\n## Preserving duplicate classes\n\nThis plugin automatically removes duplicate classes from your class lists. However, this can cause issues in some templating languages, like Fluid or Blade, where we can't distinguish between classes and the templating syntax.\n\nIf removing duplicate classes is causing issues in your project, you can use the `tailwindPreserveDuplicates` option to disable this behavior:\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \"tailwindPreserveDuplicates\": true,\n}\n```\n\nWith this configuration, anything we perceive as duplicate classes will be preserved:\n\n```html\n\u003Cdiv\n  class=\"\n    {f:if(condition: isCompact, then: 'grid-cols-3', else: 'grid-cols-5')}\n    {f:if(condition: isDark, then: 'bg-black\u002F50', else: 'bg-white\u002F50')}\n    grid gap-4 p-4\n  \"\n>\n\u003C\u002Fdiv>\n```\n\n## Compatibility with other Prettier plugins\n\nThis plugin uses Prettier APIs that can only be used by one plugin at a time, making it incompatible with other Prettier plugins implemented the same way. To solve this we've added explicit per-plugin workarounds that enable compatibility with the following Prettier plugins:\n\n- `@ianvs\u002Fprettier-plugin-sort-imports`\n- `@prettier\u002Fplugin-pug`\n- `@shopify\u002Fprettier-plugin-liquid`\n- `@trivago\u002Fprettier-plugin-sort-imports`\n- `prettier-plugin-astro`\n- `prettier-plugin-css-order`\n- `prettier-plugin-jsdoc`\n- `prettier-plugin-multiline-arrays`\n- `prettier-plugin-organize-attributes`\n- `prettier-plugin-organize-imports`\n- `prettier-plugin-svelte`\n- `prettier-plugin-sort-imports`\n\nOne limitation with this approach is that `prettier-plugin-tailwindcss` *must* be loaded last.\n\n```json5\n\u002F\u002F .prettierrc\n{\n  \u002F\u002F ..\n  \"plugins\": [\n    \"prettier-plugin-svelte\",\n    \"prettier-plugin-organize-imports\",\n    \"prettier-plugin-tailwindcss\" \u002F\u002F MUST come last\n  ]\n}\n```\n","这是一个用于Tailwind CSS的Prettier插件，能够根据推荐的类顺序自动排序CSS类。该插件使用TypeScript编写，支持Prettier v3+和Tailwind CSS v3.0+版本。它不仅提供自动排序功能，还允许用户通过配置指定Tailwind样式表路径或JavaScript配置文件路径，以适应项目特定的需求。此外，用户还可以自定义额外需要排序的属性列表。此工具非常适合那些希望保持代码风格一致且易于维护的前端开发团队，在使用Tailwind CSS构建网站或应用时尤为有用。",2,"2026-06-11 03:37:17","high_star"]