Tailwind CSS没有显示变化。[React + Tailwindcss]

huangapple go评论65阅读模式
英文:

Tailwind CSS is not showing the changes. [React + Tailwindcss]

问题

I am in the middle of making an Instagram Clone SSR project using React and Tailwind.CSS but I got stuck with Tailwind CSS I have installed the required dependencies, changed scripts that was needed also added paths in tailwindcss.config.js, added @tailwind directives to the app.css file also but whatever is written in class names is not reflecting in the result after npm start

Login.js file for Login Page

import { useContext, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import FirebaseContext from "../context/firebase";
import "../styles/app.css";

export default function Login() {
  const navigate = useNavigate();
  const { firebase } = useContext(FirebaseContext);

  const [emailAddress, setEmailAddress] = useState("");
  const [password, setPassword] = useState("");

  const [error, setError] = useState("");
  const isInvalid = password === "" || emailAddress === "";

  const handleLogin = () => {};

  useEffect(() => {
    document.title = "Login - Instagram";
  }, []);
  return (
    <div className='container flex mx-auto max-w-screen-md items-center h-screen'>
      <div className='flex w-3/5'>
        <img
          src='/images/iphone-with-profile.jpg'
          alt='iPhone with Instagram App'
          className='max-w-full'
        />
      </div>
      <div className='flex flex-col w-2/5'>
        <p>This is the Form</p>
      </div>
    </div>
  );
}

package.json file - scripts and dependencies

{
  "name": "instagram",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "date-fns": "^2.29.3",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-loading-skeleton": "^3.1.0",
    "react-router-dom": "^6.8.1",
    "react-scripts": "^5.0.1",
    "web-vitals": "^3.1.1"
  },
  "scripts": {
    "build:css": "postcss src/styles/tailwind.css -o src/styles/app.css",
    "watch:css": "postcss src/styles/tailwind.css -o src/styles/app.css --watch",
    "react-scripts:start": "react-scripts start",
    "start": "run-p watch:css react-scripts:start",
    "build": "run-s build:css 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.13",
    "babel-eslint": "^10.1.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-config-prettier": "^8.6.0",
    "eslint-plugin-import": "^2.27.5",
    "eslint-plugin-jsx-a11y": "^6.7.1",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-react": "^7.32.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-scope": "^7.1.1",
    "npm-run-all": "^4.1.5",
    "postcss": "^8.4.21",
    "postcss-cli": "^10.1.0",
    "postcss-loader": "^7.0.2",
    "prettier": "^2.8.4",
    "tailwindcss": "^3.2.6"
  }
}

postcss.config.js

module.exports = {
  plugins: [require("tailwindcss"), require("autoprefixer")],
};

tailwind.config.js

module.exports = {
  future: {
    removeDeprecatedGapUtilities: true,
  },
  theme: {
    extend: {},
  },
  variants: {},
  plugins: [],
  content: ["./src/**/*.html", "./src/**/*.jsx", "./public/index.html"],
};

And in my app.css file, the original file contained the @tailwind commands (base, utilities, components), but they were replaced with the generated CSS code that follows the defined styles in the Tailwind CSS configuration.

英文:

I am in the middle of making an Instagram Clone SSR project using React and Tailwind.CSS but I got stuck with Tailwind CSS I have installed the required dependencies, changed scripts that was needed also added paths in tailwindcss.config.js, added @tailwind directives to the app.css file also but whatever is written in class names is not reflecting in the result after npm start

Login.js file for Login Page

import { useContext, useEffect, useState } from &quot;react&quot;;
import { useNavigate } from &quot;react-router-dom&quot;;
import FirebaseContext from &quot;../context/firebase&quot;;
import &quot;../styles/app.css&quot;;
export default function Login() {
const navigate = useNavigate();
const { firebase } = useContext(FirebaseContext);
const [emailAddress, setEmailAddress] = useState(&quot;&quot;);
const [password, setPassword] = useState(&quot;&quot;);
const [error, setError] = useState(&quot;&quot;);
const isInvalid = password === &quot;&quot; || emailAddress === &quot;&quot;;
const handleLogin = () =&gt; {};
useEffect(() =&gt; {
document.title = &quot;Login - Instagram&quot;;
}, []);
return (
&lt;div className=&#39;container flex mx-auto max-w-screen-md items-center h-screen&#39;&gt;
&lt;div className=&#39;flex w-3/5&#39;&gt;
&lt;img
src=&#39;/images/iphone-with-profile.jpg&#39;
alt=&#39;iPhone with Instagram App&#39;
className=&#39;max-w-full&#39;
/&gt;
&lt;/div&gt;
&lt;div className=&#39;flex flex-col w-2/5&#39;&gt;
&lt;p&gt;This is the Form&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
);
}

package.json file - scripts and dependencies

{
&quot;name&quot;: &quot;instagram&quot;,
&quot;version&quot;: &quot;0.1.0&quot;,
&quot;private&quot;: true,
&quot;dependencies&quot;: {
&quot;@testing-library/jest-dom&quot;: &quot;^5.16.5&quot;,
&quot;@testing-library/react&quot;: &quot;^13.4.0&quot;,
&quot;@testing-library/user-event&quot;: &quot;^13.5.0&quot;,
&quot;date-fns&quot;: &quot;^2.29.3&quot;,
&quot;prop-types&quot;: &quot;^15.8.1&quot;,
&quot;react&quot;: &quot;^18.2.0&quot;,
&quot;react-dom&quot;: &quot;^18.2.0&quot;,
&quot;react-loading-skeleton&quot;: &quot;^3.1.0&quot;,
&quot;react-router-dom&quot;: &quot;^6.8.1&quot;,
&quot;react-scripts&quot;: &quot;^5.0.1&quot;,
&quot;web-vitals&quot;: &quot;^3.1.1&quot;
},
&quot;scripts&quot;: {
&quot;build:css&quot;: &quot;postcss src/styles/tailwind.css -o src/styles/app.css&quot;,
&quot;watch:css&quot;: &quot;postcss src/styles/tailwind.css -o src/styles/app.css --watch&quot;,
&quot;react-scripts:start&quot;: &quot;react-scripts start&quot;,
&quot;start&quot;: &quot;run-p watch:css react-scripts:start&quot;,
&quot;build&quot;: &quot;run-s build:css react-scripts:build&quot;,
&quot;test&quot;: &quot;react-scripts test&quot;,
&quot;eject&quot;: &quot;react-scripts eject&quot;
},
&quot;eslintConfig&quot;: {
&quot;extends&quot;: [
&quot;react-app&quot;,
&quot;react-app/jest&quot;
]
},
&quot;browserslist&quot;: {
&quot;production&quot;: [
&quot;&gt;0.2%&quot;,
&quot;not dead&quot;,
&quot;not op_mini all&quot;
],
&quot;development&quot;: [
&quot;last 1 chrome version&quot;,
&quot;last 1 firefox version&quot;,
&quot;last 1 safari version&quot;
]
},
&quot;devDependencies&quot;: {
&quot;autoprefixer&quot;: &quot;^10.4.13&quot;,
&quot;babel-eslint&quot;: &quot;^10.1.0&quot;,
&quot;eslint-config-airbnb&quot;: &quot;^19.0.4&quot;,
&quot;eslint-config-prettier&quot;: &quot;^8.6.0&quot;,
&quot;eslint-plugin-import&quot;: &quot;^2.27.5&quot;,
&quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.7.1&quot;,
&quot;eslint-plugin-prettier&quot;: &quot;^4.2.1&quot;,
&quot;eslint-plugin-react&quot;: &quot;^7.32.2&quot;,
&quot;eslint-plugin-react-hooks&quot;: &quot;^4.6.0&quot;,
&quot;eslint-scope&quot;: &quot;^7.1.1&quot;,
&quot;npm-run-all&quot;: &quot;^4.1.5&quot;,
&quot;postcss&quot;: &quot;^8.4.21&quot;,
&quot;postcss-cli&quot;: &quot;^10.1.0&quot;,
&quot;postcss-loader&quot;: &quot;^7.0.2&quot;,
&quot;prettier&quot;: &quot;^2.8.4&quot;,
&quot;tailwindcss&quot;: &quot;^3.2.6&quot;
}
}

postcss.config.js

module.exports = {
plugins: [require(&quot;tailwindcss&quot;), require(&quot;autoprefixer&quot;)],
};

tailwind.config.js

module.exports = {
future: {
removeDeprecatedGapUtilities: true,
},
theme: {
extend: {},
},
variants: {},
plugins: [],
content: [&quot;./src/**/*.html&quot;, &quot;./src/**/*.jsx&quot;, &quot;./public/index.html&quot;],
};

And in my app.css file the original file contained the "@tailwind" commands (base, utilities, components), but they were replaced with the generated CSS code that follows the defined styles in the Tailwind CSS configuration.

答案1

得分: 1

你应该删除 classNames 中的花括号:

&lt;div className=&#39;container flex mx-auto max-w-screen-md items-center h-screen&#39;&gt;

英文:

You should remove the curly braces in your classNames :

&lt;div className=&#39;container flex mx-auto max-w-screen-md items-center h-screen&#39;&gt;

答案2

得分: 0

我认为这是因为你组件的扩展名是.js,但你的Tailwind配置中没有包含.js文件(content属性)。我建议将你组件的文件扩展名更改为.jsx

英文:

I think it's because your component's extension is .js but you don't have .js files covered in your Tailwind config (content property). I would recommend changing the extension of your component's file to .jsx.

huangapple
  • 本文由 发表于 2023年2月10日 16:15:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75408454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定