简体   繁体   中英

Vite Vanilla build with Tailwind doesn't work

I created a vanilla js project with Vite and installed Tailwind as the docs says. When I run in dev mode the classes works, but when I build the dist folder and serve that build it doesn't.

My postcss.config.js is this

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

And my tailwind config is this

module.exports = {
  purge: [
    './src/**/*.html',
    './src/**/*.js',
  ],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

You can follow these steps to resolve the issue:

  1. Remove the code from your main.js file (part of Vite's template).

  2. You may also want to remove the #app block from the styles.css (part of Vite's template).

  3. Add the following line to your index.html :

     <link rel="stylesheet" href="/style.css">
  4. Now in the <body> , you can use Tailwind like this:

     <div class="text-2xl">Hello, World!</div>

PS: thanks to this video (from 6:11 to 7:36) for the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM