Tailwind4 中 taildwind.config.js 废除后的全局变量修改方法(npx tailwindcss init失效,npm ERR! could not determine ex)

npx tailwindcss init报错 npm ERR! could not determine executable to run

我在配置好Tailwind4之后(具体配置见我的另一篇文章《在Vue3 + Vite 项目中使用 Tailwind CSS 4.0》),发现对比之前的版本少了taildwind.config.js文件。于是,我想通过 npx tailwindcss init新建这个文件。但是出现了报错。

报错详情:

npm ERR! could not determine executable to run

npm ERR! A complete log of this run can be found in: C:\Users\Administrator\AppData\Local\npm-cache\_logs\2025-02-16T04_11_16_774Z-debug-0.log

在这里插入图片描述

Tailwind4不再支持 taildwind.config.js

出现上文的问题在于 Tailwind4不再支持 taildwind.config.js

参考文章:https://github.com/tailwindlabs/tailwindcss/discussions/15820
在这里插入图片描述

找到官网中确实详细说明了:

官网地址 https://tailwindcss.com/blog/tailwindcss-v4#css-first-configuration

One of the biggest changes in Tailwind CSS v4.0 is the shift from configuring your project in JavaScript to configuring it in CSS.

Instead of a tailwind.config.js file, you can configure all of your customizations directly in the CSS file where you import Tailwind, giving you one less file to worry about in your project:

在这里插入图片描述

现在直接在css中@theme修改即可达到与 taildwind.config.js 相同的效果

还是在我之前文章中的 src\styles\index.css中添加下面所述代码: 《在Vue3 + Vite 项目中使用 Tailwind CSS 4.0》

@import "tailwindcss";

@theme {
  --color-mint-500: oklch(0.72 0.11 178);
  --text-xs: 0.35rem;
}

在这里插入图片描述

  • 在浏览器中就可以看到 --text-xs这个值被修改成了我定义的 0.35rem而不是默认值

在这里插入图片描述

在这里插入图片描述

版本3的下载方法

$ npm install -D tailwindcss@3 postcss autoprefixer
$ npx tailwindcss init -p

参考文章:https://github.com/tailwindlabs/tailwindcss/discussions/15820

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值