vite-plugin-tailwind-autoreference

Automatically `@reference` your Tailwind CSS file in Svelte, Vue & other SFC files.
5,787
Install
npm install vite-plugin-tailwind-autoreference
Latest Version:0.2.4
License:MIT
Last Updated:Jan 31, 2026
Links: npm
Maintainer: snuffydev

vite-plugin-tailwind-autoreference

Find me on npm!

A Vite plugin which will automatically add @reference directives to your Single File Components (SFCs) <style> blocks.

This plugin is designed to work with Tailwind CSS v4, and is setup to target Svelte and Vue files out of the box.

  • :muscle: Flexible - can target any desired SFC file type!
  • :sunglasses: Easy - just add the plugin to your Vite config!
  • :robot: Automatic - no need to manually add @reference directives!

Compatibility

This plugin targets the following dependency versions:

:exclamation: The compatibility list is not exhaustive, the plugin may work with other Vite/Node versions, but it is not guaranteed.

Installation

To install the plugin, run the following command:

npm
npm install vite-plugin-tailwind-autoreference --save-dev
pnpm
pnpm add vite-plugin-tailwind-autoreference --save-dev
bun
bun add vite-plugin-tailwind-autoreference --dev

Usage

To get started, you need to add the plugin to your Vite config file. Here's a basic example using SvelteKit:

// vite.config.js
import { defineConfig } from 'vite';
import tailwindcss from 'tailwindcss';
import { sveltekit } from '@sveltejs/kit/vite';
import twAutoReference from 'vite-plugin-tailwind-autoreference';

export default defineConfig({
  plugins: [
    sveltekit(),
    twAutoReference({
        cssRoot: 'src/app.css', // Specify the path to the CSS file that imports tailwindcss
        include: [
            // Patterns to include specific file types
        ]
    }),
    tailwindcss(),
  ] // Make sure tailwindcss is added after the autoreference plugin
});

Options

The plugin accepts the following options:

  • cssRoot (required): The path to the CSS file that imports Tailwind CSS. This is used to determine the root of the CSS files in your project.
  • include (optional): A pattern, or an array of patterns, to include specific files. The default targets are Svelte and Vue files.

Using the include option

The include option allows you to specify which files to include in the plugin's processing.

It's recommended to use this syntax to ensure proper processing of your styles. /\.ext\?.*type=style/ where ext is the file extension you want to target. Appending ?type=style ensures that the plugin processes only the style blocks for the specified file type.

Related Packages

vite-plugin-vue-tailwind-auto-reference

Automatically @reference your Tailwind CSS file in Vue SFC blocks.

51,792 34
vite-plugin-pwa

Zero-config PWA for Vite

140,031,941 4,301
@miyaoka/vite-plugin-doc-block

Vite plugin to strip custom blocks from Vue SFC

6,898 0
vite-plugin-vue-i18n-sfc-auto-import

Enable component-scoped i18n with Option API when using vue-i18n in composition...

1,835 1

Version History

Version Released License
0.2.4 MIT
0.2.3 MIT
0.2.2 MIT
0.2.1 MIT
0.2.0 MIT