import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
export default defineConfig({
plugins: [react(), tailwindcss()],
// Previously tried with:
// css: {
// postcss: {
// plugins: [
// tailwindcss(), // Caused TS2769 error: Type Plugin<any>[] is not assignable to type AcceptedPlugin
// ],
// },
// },
});
我的index.css
/* here google fonts */
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
margin: 0;
padding: 0;
font-family: "Inter", sans-serif;
MyMain.tsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from './App'
import './index.css'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
在这里我的包裹。
{
"name": "...",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"classnames": "^2.5.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-responsive": "^10.0.1",
"swiper": "^11.2.5"
},
"devDependencies": {
"@eslint/js": "^9.21.0",
"@tailwindcss/vite": "^4.0.14",
"@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.21",
"eslint": "^9.21.0",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^15.15.0",
"postcss": "^8.5.3",
"tailwindcss": "^4.0.14",
"typescript": "~5.7.2",
"typescript-eslint": "^8.24.1",
"vite": "^6.2.0"
}
}
我没有使用PostCSS Config。我使用尾风完全适合内容模式的文件。我尝试了所有的titetaly,重建,重播,重新安装
node_modules
,并在
safelist
中添加。那么有什么问题的原因呢?
看起来您已经安装了parwindcss v4,但是您正在使用不弃用的指令。从v4开始,CSS中的参考障碍物参考:
tailwind.config