11

I'm using vite 0.16.6 and wanted to migrated a vuepress site to using vite.

However I was unsure how to configure vite to using tailwindcss.

in my index.css

@tailwind base;
@tailwind components;
@tailwind utilities;

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
1

6 Answers 6

32

After some digging, looks like that we have to include a postcss.config.js in the root directory of the application

module.exports = {
  plugins: [
    // ...
    require('tailwindcss'),
    require('autoprefixer'),
    // ...
  ]
}

for Vite V4

OTOMOTIF/a/79538862/2312051

4
  • 1
    doc tailwindcss.com/docs/guides/vite is missing this part =.=" Commented Jan 7, 2022 at 18:52
  • 1
    putting the postcss.config.js in the app root was what fixed it for me. Optionally, you can edit your vite.config.js to specify the location of your postcss.config.js file. vitejs.dev/config/#css-postcss Commented Jan 28, 2022 at 1:47
  • 3
    I love how after 2 years this answer is still applicable :D
    – Denis Tsoi
    Commented Jan 28, 2022 at 3:01
  • this worked after i migrated from create-react-app v5 to vite
    – Abe Caymo
    Commented Oct 4, 2022 at 7:32
4

Vite has built-in support for PostCSS:

npm -D install tailwindcss autoprefixer

vite.config.ts

import { defineConfig } from "vite"
import tailwind from "tailwindcss";
import autoprefixer from "autoprefixer";

export default defineConfig({
  css: {
    postcss: {
      plugins: [tailwind, autoprefixer],
    }
  }
})
2
yarn add tailwindcss @tailwindcss/typography @tailwindcss/ui -D

yarn tailwind init note : you can use npm

crate file : postcss.config.js and add :

module.exports={
 plugins: [
  require('tailwindcss'),
  require('autoprefixer'),
  ]
 }

Replace the contents of src/index.css file with:

@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
2

I wrote a vite tailwind plugin https://github.com/axe-me/vite-plugin-tailwind

it enabled the jit compiler by default and it also have a tailwind config viewer

0
2

Although this is an old question, newcomers still need relevant information. The question originally referred to v3, where TailwindCSS could only be integrated into Vite via PostCSS. Many good answers were provided for this implementation.

TailwindCSS v4

However, since January 2025, with the release of TailwindCSS v4, a new @tailwindcss/vite Vite plugin has been introduced, allowing direct integration of TailwindCSS into Vite without PostCSS. See:

npm install tailwindcss @tailwindcss/vite

vite.config.js

import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
  plugins: [
    tailwindcss(),
  ],
})

app.css

@import "tailwindcss";
1
  • agreed - I've updated the title to ensure it's V0-V3
    – Denis Tsoi
    Commented Apr 7 at 10:10
-1

If you want to create a vite project that includes tailwind, the create-vite-tailwind initializer package is what you want.

$ npm create-vite-tailwind
...
$ npm run dev

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.