无法在React项目中上载taiwindcss

Unable to upload taiwind CSS in React project(无法在React项目中上载taiwindcss)

本文介绍了无法在React项目中上载taiwindcss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Reaction项目中使用TailWind CSS。我遵循了here中的文档中给出的步骤。但在完成所有步骤后,我看不到顺风CSS的变化。 我像这样添加文件Home.js中的样式,

import React from "react";
    .
    .
    .

  return (
    <>
        <div className="bg-red-500 h-96 py-80">
        <h1 className="text-3xl font-bold underline bg-yellow-400">
      Hello world!
    </h1>
        </div>
    </>
  );
};

export default Home;

但它没有显示任何内容 以下是必需的文件:

Package.json

{
  "name": "authlogin-boilerplate",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "express": "^4.17.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.1.1",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "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.2",
    "postcss": "^8.4.5",
    "tailwindcss": "^3.0.11"
  }
}

trawind.config.js

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

App.js

import { useState } from "react";
import "./App.css";
import "./index.css";
import Navbar from "./components/Navbar";
import Home from "./components/Home";
import About from "./components/About";
import SignupPage from "./components/SignupPage";
import LoginPage from "./components/LoginPage";
import ForgotPasswordPage from "./components/ForgotPasswordPage";
import ChangePasswordPage from "./components/ChangePasswordPage";
import Alert from "./components/Alert";

import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

function App() {
  const [alert, setAlert] = useState(null);

  const showAlert = (message, type) => {
    setAlert({ msg: message, type: type });
    setTimeout(() => setAlert(null), 1500);
  };

  return (
    <>
      <Router>
        <Navbar showAlert={showAlert} />
        <Alert alert={alert} />
        <Routes>
          <Route path="/" element={<Home showAlert={showAlert} />} />
         .
         .
      </Router>
    </>
  );
}

export default App;

index.css

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

另外,我的项目结构是

我注意到,在我的index.css中,我收到了这样的警告

我不知道原因,我已重新启动笔记本电脑两次,但不起作用。

推荐答案

这不起作用,因为您尚未将CRACO层添加到您的Reaction应用程序。您的设置很好,但仍有一些需要添加的内容,您只需在您的Reaction应用程序根目录中运行npm install @craco/craco,并使用如下图所示的Start、Build和Eject命令的新值更改您的Package.json文件,最后再次启动您的服务器,这将会起作用。

这篇关于无法在React项目中上载taiwindcss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法在React项目中上载taiwindcss

基础教程推荐