Tailwind CSS @apply Unknown at rule @apply scss(unknownAtRules) 解决方案

vscode 警告提示如下:

@tailwind base;
^^^^^^^^^ 
Unknown at rule @tailwind css(unknownAtRules)
@layer base {
  * {
    @apply text-gray-dark;
    ^^^^^^^^ 
    Unknown at rule @apply css(unknownAtRules)
  }
}

解决方法:

  1. 在根目录 .vscode 文件夹下 .vscode/settings.json 添加
    "css.customData": [".vscode/tailwindcss.json"]
    
  2. 创建 .vscode/tailwindcss.json
	{
  "version": 1.1,
  "atDirectives": [
    {
      "name": "@tailwind",
      "description": "Use the `@tailwind` directive to insert Tailwind's `base`, `components`, `utilities` and `screens` styles into your CSS.",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#tailwind"
        }
      ]
    },
    {
      "name": "@apply",
      "description": "Use the `@apply` directive to inline any existing utility classes into your own custom CSS. This is useful when you find a common utility pattern in your HTML that you’d like to extract to a new component.",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#apply"
        }
      ]
    },
    {
      "name": "@responsive",
      "description": "You can generate responsive variants of your own classes by wrapping their definitions in the `@responsive` directive:\n```css\n@responsive {\n  .alert {\n    background-color: #E53E3E;\n  }\n}\n```\n",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#responsive"
        }
      ]
    },
    {
      "name": "@screen",
      "description": "The `@screen` directive allows you to create media queries that reference your breakpoints by **name** instead of duplicating their values in your own CSS:\n```css\n@screen sm {\n  /* ... */\n}\n```\n…gets transformed into this:\n```css\n@media (min-width: 640px) {\n  /* ... */\n}\n```\n",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#screen"
        }
      ]
    },
    {
      "name": "@variants",
      "description": "Generate `hover`, `focus`, `active` and other **variants** of your own utilities by wrapping their definitions in the `@variants` directive:\n```css\n@variants hover, focus {\n   .btn-brand {\n    background-color: #3182CE;\n  }\n}\n```\n",
      "references": [
        {
          "name": "Tailwind Documentation",
          "url": "https://tailwindcss.com/docs/functions-and-directives#variants"
        }
      ]
    }
  ]
}
### 如何在 Appkly 中使用 TailwindCSS 进行样式设计 #### 安装 Tailwind CSS 为了能够在项目中使用 Tailwind CSS,在开始之前需要确保已经安装了 Node.js 和 npm。接着可以在命令行工具里执行以下命令来初始化一个新的 npm 项目并安装 Tailwind CSS 及其依赖项: ```bash npm init -y npm install tailwindcss postcss autoprefixer npx tailwindcss init -p ``` 这会创建 `tailwind.config.js` 文件以及 PostCSS 的配置文件。 #### 配置 Tailwind CSS 编辑刚生成的 `tailwind.config.js` 来定制化 Tailwind 的设置,比如主题、变体等。对于大多数情况,默认配置就足够用了。如果想要扩展功能,则可以根据官方文档调整此文件的内容[^1]。 #### 导入 Tailwind CSS 到项目 接下来要做的就是在项目的入口 CSS 文件(通常是 `src/styles.css` 或者类似的路径下)引入 Tailwind 提供的基础样式表: ```css @import "tailwindcss/base"; @import "tailwindcss/components"; @import "tailwindcss/utilities"; ``` 这样做之后就能在整个应用程序范围内访问 Tailwind 提供的各种实用类名了。 #### 构建过程中的处理 为了让 Webpack 正确打包这些资源,还需要修改 webpack 配置以支持 PostCSS 处理器。通常情况下,Appkly 已经集成了对 PostCSS 的良好支持,所以只需要确认 `.postcssrc.json` 存在并且包含了必要的插件即可: ```json { "plugins": { "autoprefixer": {}, "tailwindcss": "./tailwind.config.js" } } ``` 以上步骤完成后,当运行开发服务器或是构建生产版本时,Tailwind 的样式就会被正确编译进最终输出的 CSS 文件之中。 #### 使用 Tailwind 组件库 (可选) 除了直接利用 Tailwind 自带的功能外,还可以考虑采用一些基于 Tailwind 开发的 UI 库,例如 HeadlessUI 或 Heroicons 等,它们提供了现成的设计组件,能够进一步简化界面搭建的工作量。 通过上述操作,便可在 Appkly 平台上顺利运用 Tailwind CSS 实现美观且响应式的网页布局效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值