【问题标题】:Tailwind css 3.0.5 classes is not working with reactTailwind css 3.0.5 类不适用于反应
【发布时间】:2022-01-20 23:36:29
【问题描述】:

Tailwind css 3.0.5 不适用于 react。我已经按照顺风 css 的官方安装指南 (https://tailwindcss.com/docs/guides/create-react-app) 安装了顺风 css。 我写的代码如下。

package.json

{
  "name": "react-complete-guide",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.6",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.5.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "autoprefixer": "^10.4.0",
    "postcss": "^8.4.5",
    "tailwindcss": "^3.0.7"
  }
}

src/index.css

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

postcss.config.js

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

tailwind.config.js

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

src/app.js

import "./index.css";

function App() {
  return (
    <h1 className="text-3xl font-bold underline">
      Hello world!
    </h1>
  );
}

export default App;

【问题讨论】:

  • 请添加您的代码
  • @AselaPriyadarshana 添加了代码。请立即查看。

标签: reactjs tailwind-css


【解决方案1】:

我认为你需要更新你的 create-react-app 版本,你使用的是版本 4,它需要像 Craco 这样的东西来让你在本地覆盖 PostCSS 配置

尝试使用此命令全局更新您的 create-react-app npm install -g create-react-app, 然后再试这一步https://tailwindcss.com/docs/guides/create-react-app

仅在当前项目上更新您的 create-react-app npm install react-scripts@latest

【讨论】:

  • 谢谢!我将我的 react-scripts 版本更改为最新版本“5.0.0”,然后运行 ​​npm install
  • 是的,实际上也很有效
猜你喜欢
  • 2022-10-19
  • 1970-01-01
  • 2021-09-04
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
  • 2021-02-14
  • 2022-10-22
  • 1970-01-01
相关资源
最近更新 更多