使用 Craco 从 Tailwind v2 升级到 v3 React Js 的问题
Issue with Upgrade from Tailwind v2 to v3 React Js using Craco
我使用的是 Tailwind v2,当我将它升级到 v3 时,出现了 Postcss 8 错误 (错误:PostCSS 插件 tailwindcss 需要 PostCSS 8。)。我试图解决此错误但没有成功。有什么办法可以在 React Js 中使用 Tailwind Cli。
Error ScreenShoot
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.4.0",
"@formatjs/intl-pluralrules": "^4.1.5",
"@formatjs/intl-relativetimeformat": "^9.3.2",
"@headlessui/react": "^1.4.2",
"@heroicons/react": "^1.0.5",
"@manaflair/redux-batch": "^1.0.0",
"@reduxjs/toolkit": "^1.6.2",
"@tailwindcss/forms": "^0.4.0",
"@tailwindcss/line-clamp": "^0.3.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-apexcharts": "^1.3.9",
"react-autocomplete": "^1.8.1",
"react-datepicker": "^4.5.0",
"react-dom": "^17.0.2",
"web-vitals": "^1.0.1",
"yup": "0.29.0"
},
"devDependencies": {
"autoprefixer": "^10.4.2",
"copyfiles": "2.1.1",
"postcss": "^8.4.5",
"prettier": "^1.19.1",
"sass": "1.32.8",
"serve": "11.2.0",
"tailwindcss": "^3.0.12"
},
"scripts": {
"start": "craco start",
"dev": "TAILWIND_MODE=watch craco start",
"build": "craco build",
"test": "craco 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"
]
}
}
tailwindcss v3 只支持Postcss8,目前只有create-react-app v5 支持Postcss8。所以你需要将 create-react-app 升级到 v5。
在 create-react-app v5 中也不需要 craco
为了安全起见,首先确保在迁移之前结帐到不同的分支或将代码推送到 github。
1.First 运行 npm uninstall @craco/craco autoprefixer postcss tailwindcss
删除 craco.config.js 文件
删除 tailwind.config.js
现在只需按照 offical tailwindcss 文档
2. 运行 npm install -D tailwindcss postcss autoprefixer
3.npx tailwindcss init -p
从 tailwindcss 文档中复制粘贴 tailwind.config.js 文件
4.npm install react-scripts@latest
5.现在npm start
6. 更改 npm 脚本:
“开始”:“反应脚本开始”
“构建”:“反应脚本构建”
“测试”:“反应脚本测试”
“弹出”:“反应脚本弹出”
稍后将您以前的 tailwind.config 主题粘贴到新的 tailwind.config.js 文件中。
步骤的顺序可能重要也可能无关紧要,但遵循这些步骤对我有用。
我使用的是 Tailwind v2,当我将它升级到 v3 时,出现了 Postcss 8 错误 (错误:PostCSS 插件 tailwindcss 需要 PostCSS 8。)。我试图解决此错误但没有成功。有什么办法可以在 React Js 中使用 Tailwind Cli。 Error ScreenShoot
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.4.0",
"@formatjs/intl-pluralrules": "^4.1.5",
"@formatjs/intl-relativetimeformat": "^9.3.2",
"@headlessui/react": "^1.4.2",
"@heroicons/react": "^1.0.5",
"@manaflair/redux-batch": "^1.0.0",
"@reduxjs/toolkit": "^1.6.2",
"@tailwindcss/forms": "^0.4.0",
"@tailwindcss/line-clamp": "^0.3.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-apexcharts": "^1.3.9",
"react-autocomplete": "^1.8.1",
"react-datepicker": "^4.5.0",
"react-dom": "^17.0.2",
"web-vitals": "^1.0.1",
"yup": "0.29.0"
},
"devDependencies": {
"autoprefixer": "^10.4.2",
"copyfiles": "2.1.1",
"postcss": "^8.4.5",
"prettier": "^1.19.1",
"sass": "1.32.8",
"serve": "11.2.0",
"tailwindcss": "^3.0.12"
},
"scripts": {
"start": "craco start",
"dev": "TAILWIND_MODE=watch craco start",
"build": "craco build",
"test": "craco 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"
]
}
}
tailwindcss v3 只支持Postcss8,目前只有create-react-app v5 支持Postcss8。所以你需要将 create-react-app 升级到 v5。 在 create-react-app v5 中也不需要 craco
为了安全起见,首先确保在迁移之前结帐到不同的分支或将代码推送到 github。
1.First 运行 npm uninstall @craco/craco autoprefixer postcss tailwindcss
删除 craco.config.js 文件
删除 tailwind.config.js
现在只需按照 offical tailwindcss 文档
2. 运行 npm install -D tailwindcss postcss autoprefixer
3.npx tailwindcss init -p
从 tailwindcss 文档中复制粘贴 tailwind.config.js 文件
4.npm install react-scripts@latest
5.现在npm start
6. 更改 npm 脚本:
“开始”:“反应脚本开始”
“构建”:“反应脚本构建”
“测试”:“反应脚本测试”
“弹出”:“反应脚本弹出”
稍后将您以前的 tailwind.config 主题粘贴到新的 tailwind.config.js 文件中。
步骤的顺序可能重要也可能无关紧要,但遵循这些步骤对我有用。