NodeJS Tailwind CSS不适用于React应用程序

zed5wv10  于 2022-12-22  发布在  Node.js
关注(0)|答案(3)|浏览(173)

我正在尝试添加顺风css与React应用程序。我遵循了顺风文档,如何设置顺风与React。
我用最新版本的tailwind试过了,我检查了Nodejs和npm安装的很好。
但是当我运行npm run start的时候,它总是得到一个错误,我无法修复这个问题。

package.json

{
  "name": "tailwind-css",
  "version": "0.1.0",
  "homepage": "",
  "private": true,
  "dependencies": {
    "@craco/craco": "^6.1.2",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.3"
  },
  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "craco test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "engines": {
    "npm": "6.14.6",
    "node": "12.18.4"
  },
  "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": "^9.8.6",
    "postcss": "^7.0.36",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.2"
  }
}

请任何人帮助。

xfb7svmp

xfb7svmp1#

如果你遵循顺风文档的方式,那么试试这个,在package.json

"scripts": {
    "start": "craco start && postcss src/css/app.css -o public/app.css", <--- need to inser postcss script as your css reference path.
    "build": "craco build",

并像这样检查craco.config.js

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

快乐编码!

z9smfwbn

z9smfwbn2#

只需通过以下方式将您的react-script从v4更新为最新的5版本:npm安装react-scripts@latest。如果您将继续使用版本4,则必须使用craco
这对我很有帮助

bkhjykvo

bkhjykvo3#

将此内容写入tailwind.config.js
模块.导出=

{
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}"
  ].
..///
}

相关问题