小编Dav*_*hoi的帖子

Tailwind 使用 vite + React 时不清爽

我用 vite + React + Typescript 启动了一个项目并安装了 tailwind。一切都很顺利,直到我在 /src 中创建了一个子文件夹并在子文件夹内的文件中添加了样式。顺风的自动构建或观察模式停止工作。

例如,当样式位于 /src/App.tsx 中时,一切正常,但如果我在 /src/components/Header.tsx 中添加样式并在 App.tsx 中导入该组件,则 tailwind css 文件不会自动构建。

重新启动服务器确实可以正确应用新样式。

这就是我的文件的样子:

tailwind.config.js

module.exports = {
    content: ["./index.html", "./src/**/*.{html,ts,tsx}", "./src/*.{ts,tsx}"],
    theme: {
        borderColor: {
            black: "#000",
        },
        borderWidth: {
            1: 1,
        },
        extend: {
            colors: {
                custom1: "#F5A",
            },
        },
    },
    plugins: [],
};
Run Code Online (Sandbox Code Playgroud)

postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}
Run Code Online (Sandbox Code Playgroud)

src/App.tsx

import "./index.css";
import Users from "./components/Users";
import Header from "./layout/header";

function App() { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs postcss tailwind-css vite

6
推荐指数
2
解决办法
8522
查看次数

标签 统计

javascript ×1

postcss ×1

reactjs ×1

tailwind-css ×1

vite ×1