After running the npm run dev, it shows this:
[plugin:vite:esbuild] The service is no longer running
My config files are properly set up although I don't have a config file for PostCSS also.
vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/postcss';
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
],
})
I tried updating the esbuild but it's still the same.
Since you're using Vite, you don't need PostCSS. TailwindCSS v4 provides a separate plugin for both Vite (@tailwindcss/vite) and PostCSS (@tailwindcss/postcss).
To inject TailwindCSS into Vite, you only need to install the following packages:
npm install tailwindcss @tailwindcss/vite
Then, modify the vite.config.js file as follows:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite' /* instead of @tailwindcss/postcss */
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
],
})
After that, you just need to insert the import into your CSS file:
@import "tailwindcss";
If you insist on using PostCSS, you only need to install the following packages:
npm install tailwindcss @tailwindcss/postcss postcss
After that, you need to associate PostCSS with Vite,
a.) modify the postcss.config.js file as follows:
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
Since Vite automatically uses PostCSS if a postcss.config.js file exists, you don't need to explicitly associate it with Vite. The installed TailwindCSS plugin will work accordingly.
vite.config.file in this case:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default {
plugins: [
react(),
],
}
b.) or modify the vite.config.js file as follows:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [
react(),
],
css: {
postcss: {
plugins: {
'@tailwindcss/postcss': {},
},
},
},
});
For inline PostCSS config, it expects the same format as postcss.config.js. But for plugins property, only array format can be used.
css.postcss - Vite DocsAfter that, you just need to insert the import into your CSS file:
@import "tailwindcss";
css.transformer - Vite DocsIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With