How do I add tailwindcss to vite?

Viewed 14128

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;
}
4 Answers

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'),
    // ...
  ]
}
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";

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
Related