{"id":50862978,"url":"https://github.com/awaiden/vite-plugin-tailwind-ref","last_synced_at":"2026-06-14T22:32:30.061Z","repository":{"id":361271971,"uuid":"1253810433","full_name":"awaiden/vite-plugin-tailwind-ref","owner":"awaiden","description":"A Vite plugin that automatically adds @reference directives to CSS files and framework style blocks (Svelte, Vue, etc.) using Tailwind CSS @apply","archived":false,"fork":false,"pushed_at":"2026-05-29T21:15:39.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-29T23:07:55.175Z","etag":null,"topics":["apply","css","reference","svelte","tailwind","tailwindcss","vite","vite-plugin","vue"],"latest_commit_sha":null,"homepage":"","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/awaiden.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-29T20:51:14.000Z","updated_at":"2026-05-29T21:25:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/awaiden/vite-plugin-tailwind-ref","commit_stats":null,"previous_names":["awaiden/vite-plugin-tailwind-ref"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/awaiden/vite-plugin-tailwind-ref","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awaiden%2Fvite-plugin-tailwind-ref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awaiden%2Fvite-plugin-tailwind-ref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awaiden%2Fvite-plugin-tailwind-ref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awaiden%2Fvite-plugin-tailwind-ref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awaiden","download_url":"https://codeload.github.com/awaiden/vite-plugin-tailwind-ref/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awaiden%2Fvite-plugin-tailwind-ref/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34340780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"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":["apply","css","reference","svelte","tailwind","tailwindcss","vite","vite-plugin","vue"],"created_at":"2026-06-14T22:32:29.350Z","updated_at":"2026-06-14T22:32:30.053Z","avatar_url":"https://github.com/awaiden.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-tailwind-ref\n\nA Vite plugin that automatically adds `@reference` directives to CSS files using Tailwind CSS `@apply`, enabling utility class usage without manual imports.\n\n## Problem\n\nWhen using Tailwind's `@apply` directive in CSS files (including framework-scoped styles like Svelte or Vue components), you typically need to manually add `@reference` directives:\n\n```css\n@reference \"tailwindcss\";\n\n.my-class {\n  @apply flex items-center;\n}\n```\n\nThis is repetitive and easy to forget.\n\n## Solution\n\nThis plugin automatically injects the necessary `@reference` directive when it detects `@apply` usage in your CSS files.\n\n## Installation\n\n```bash\nnpm install -D vite-plugin-tailwind-ref\n```\n\n## Usage\n\nAdd the plugin to your `vite.config.ts`:\n\n```typescript\nimport { defineConfig } from \"vite\";\nimport tailwindAutoReference from \"vite-plugin-tailwind-ref\";\n\nexport default defineConfig({\n  plugins: [tailwindAutoReference()],\n});\n```\n\nNow you can use `@apply` in your CSS files without manually adding `@reference` directives:\n\n```css\n.my-class {\n  @apply flex items-center justify-center;\n}\n```\n\nThe plugin will automatically inject:\n\n```css\n@reference \"tailwindcss\";\n\n.my-class {\n  @apply flex items-center justify-center;\n}\n```\n\n### Svelte\n\nFor Svelte component style blocks, configure the `include` pattern to match Svelte's style query:\n\n```typescript\n// vite.config.ts\nimport { defineConfig } from \"vite\";\nimport { svelte } from \"@sveltejs/vite-plugin-svelte\";\nimport tailwindAutoReference from \"vite-plugin-tailwind-ref\";\n\nexport default defineConfig({\n  plugins: [\n    svelte(),\n    tailwindAutoReference(\"tailwindcss\", {\n      include: [/\\.svelte\\?.*svelte\u0026type=style/],\n    }),\n  ],\n});\n```\n\nThen use `@apply` freely in your components:\n\n```svelte\n\u003cstyle\u003e\n  .my-class {\n    @apply flex items-center justify-center;\n  }\n\u003c/style\u003e\n```\n\n### Vue\n\nFor Vue component style blocks, match Vue's style query:\n\n```typescript\n// vite.config.ts\nimport { defineConfig } from \"vite\";\nimport vue from \"@vitejs/plugin-vue\";\nimport tailwindAutoReference from \"vite-plugin-tailwind-ref\";\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    tailwindAutoReference(\"tailwindcss\", {\n      include: [/\\.vue\\?.*type=style/],\n    }),\n  ],\n});\n```\n\nThen use `@apply` in your components:\n\n```vue\n\u003cstyle scoped\u003e\n.my-class {\n  @apply flex items-center justify-center;\n}\n\u003c/style\u003e\n```\n\n### Multiple frameworks / CSS files together\n\nYou can combine multiple patterns to cover both standalone CSS files and framework style blocks:\n\n```typescript\ntailwindAutoReference(\"tailwindcss\", {\n  include: [/\\.css$/, /\\.svelte\\?.*svelte\u0026type=style/],\n});\n```\n\n## Configuration\n\n### Basic Options\n\n```typescript\ntailwindAutoReference(cssFile, options);\n```\n\n#### `cssFile` (optional)\n\nType: `string | string[] | (code?: string, id?: string) =\u003e string | string[] | Promise\u003cstring | string[]\u003e`  \nDefault: `\"tailwindcss\"`\n\nThe path(s) to your Tailwind CSS file, or a function that returns the path(s).\n\n**Examples:**\n\n```typescript\n// String path\ntailwindAutoReference(\"./src/styles/tailwind.css\");\n\n// Multiple paths\ntailwindAutoReference([\"./src/styles/tailwind.css\", \"./src/styles/custom.css\"]);\n\n// Dynamic function\ntailwindAutoReference((code, id) =\u003e {\n  return id.includes(\"admin\") ? \"./admin-tailwind.css\" : \"./tailwind.css\";\n});\n\n// Async function\ntailwindAutoReference(async (code, id) =\u003e {\n  const config = await loadConfig();\n  return config.cssPath;\n});\n```\n\n#### `options` (optional)\n\nType: `object`\n\n- **`include`** (optional)  \n  Type: `FilterPattern` (string | RegExp | Array\u003cstring | RegExp\u003e)  \n  Default: `[/\\.css$/]`  \n  Patterns to match files for transformation.\n\n- **`exclude`** (optional)  \n  Type: `FilterPattern`  \n  Default: `[]`  \n  Patterns to exclude from transformation.\n\n- **`skip`** (optional)  \n  Type: `(code?: string, id?: string) =\u003e boolean`  \n  Default: `() =\u003e false`  \n  Custom function to skip transformation based on file content or path.\n\n### Advanced Examples\n\n```typescript\n// Custom include/exclude patterns\ntailwindAutoReference(\"./src/styles/tailwind.css\", {\n  include: [/\\.css$/, /\\.svelte\\?.*svelte\u0026type=style/],\n  exclude: [/node_modules/],\n});\n\n// Skip specific files\ntailwindAutoReference(\"./src/styles/tailwind.css\", {\n  skip: (code, id) =\u003e {\n    return code?.includes(\"@reference\") ?? false;\n  },\n});\n```\n\n## How It Works\n\n1. The plugin runs in Vite's `pre` enforce phase\n2. It intercepts CSS files (or files matching the configured `include` pattern)\n3. When it detects `@apply` usage, it injects the `@reference` directive\n4. If `@use` statements exist, the `@reference` is placed after the last `@use`\n5. Otherwise, it's placed at the beginning of the file\n6. Files that already contain `@reference` or `@import \"tailwindcss\"` are skipped\n\n## Requirements\n\n- Vite 5.x, 6.x, 7.x, or 8.x\n\n## Credits\n\nThis plugin is inspired by [vite-plugin-vue-tailwind-auto-reference](https://github.com/M1CK431/vite-plugin-vue-tailwind-auto-reference) by M1CK431.\n\n## License\n\nMIT\n\n## Contributing\n\nIssues and pull requests are welcome at [https://github.com/awaiden/vite-plugin-tailwind-ref](https://github.com/awaiden/vite-plugin-tailwind-ref)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawaiden%2Fvite-plugin-tailwind-ref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawaiden%2Fvite-plugin-tailwind-ref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawaiden%2Fvite-plugin-tailwind-ref/lists"}