vite is not auto reloading index.html on save after tailwind installation as postcss plugin

872 Views Asked by At

I have installed Vite with Tailwind. But after installing Tailwind , when I change the index.html file, the Vite server does not auto reload. It reloads when I save the file main.js.

tailwind.config.js

module.exports = {
  content: ['./*.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
  theme: {
    extend: {},
  },
  plugins: [],
};

postcss.config.js

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

main.js

import './style.css';

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <h1 class="text-blue-500">helo</h1>
    <script type="module" src="/main.js"></script>
  </body>
</html>


style.css

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

1

There are 1 best solutions below

0
On

If it's the <h1 class="text-blue-500">helo</h1> you expect to see, I had the same problem. Make sure you include the stylesheet in index.html:

<link rel="stylesheet" href="./src/index.css">

Tailwind is building properly when main.js gets built and updated with Vite and the stylesheet gets injected, but that's not happening for index.html when it has no reference to the stylesheet.