@Layer实用程序已使用,但没有匹配@TailWind Utilities指令

发布于 2025-02-09 21:25:24 字数 2271 浏览 3 评论 0原文

我有一个Laravel 9项目,我想使用尾风CSS。

当我将每个组件的CSS放在某些文件中以将它们分开时,它会导致错误消息,但是如果我将所有内容都放在一起。

body.css 中的错误消息

@layer使用组件,但没有匹配@TailWind组件指令。

app.css

@import "tailwind.css";

@import "body.css";

tailwind.css

@tailwind base;
@tailwind components;
@tailwind utilities;

body.css

@layer components {
    .body {
        @apply bg-sky-100
    }
}

webpack.mix.js.js

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        require("tailwindcss"),
        // require('postcss-import'),
        require("tailwindcss/nesting"),
        require('autoprefixer'),
    ])
    .webpackConfig({
        stats: {
            children: true,
        },
    })
    ;

tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
    content: [
        "./resources/**/*.blade.php",
        "./resources/**/*.js",
    ],
    theme: {
        extend: {},
    },
    plugins: [],
    darkMode: 'class',
    mode: "jit",

}

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "autoprefixer": "10.4.7",
        "axios": "^0.25",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.1.4"
    },
    "dependencies": {
        "postcss-import": "^14.1.0"
    }
}

I have a Laravel 9 project and I want to use the Tailwind CSS.

When I put each component's CSS in some files to separate them, it cause an error message but if I put all together works.

Error message in body.css

@layer components is used but no matching @tailwind components directive is present.

app.css

@import "tailwind.css";

@import "body.css";

tailwind.css

@tailwind base;
@tailwind components;
@tailwind utilities;

body.css

@layer components {
    .body {
        @apply bg-sky-100
    }
}

webpack.mix.js

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        require("tailwindcss"),
        // require('postcss-import'),
        require("tailwindcss/nesting"),
        require('autoprefixer'),
    ])
    .webpackConfig({
        stats: {
            children: true,
        },
    })
    ;

tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
    content: [
        "./resources/**/*.blade.php",
        "./resources/**/*.js",
    ],
    theme: {
        extend: {},
    },
    plugins: [],
    darkMode: 'class',
    mode: "jit",

}

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "autoprefixer": "10.4.7",
        "axios": "^0.25",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.1.4"
    },
    "dependencies": {
        "postcss-import": "^14.1.0"
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自控 2025-02-16 21:25:24

您需要使用 build noreferrer'> build time intimps 以确保 @>确保 @ @进口是在尾风处理之前处理的。

尾风文档中有一个部分,您可以参考在这里/a>。

但是,您已经在依赖项中拥有Postcss-import,应该在webpack.mix.js

仅供参考,这是推荐的订购(在”遇到一些问题:

  • PostCSS-Import
  • tailwindcss/嵌套
  • parwindcss
  • autoPreeFixer

You need to use Build-time imports to make sure @imports are handled before Tailwind processes them.

There is a section in the Tailwind docs that you can reference here.

However, you already have postcss-import in your dependencies, you should uncomment it in webpack.mix.js and move it above Tailwind, and you should be good to go.

FYI, this is the recommended ordering (referenced in nesting docs) otherwise you may run into some issues:

  • postcss-import
  • tailwindcss/nesting
  • tailwindcss
  • autoprefixer
傾旎 2025-02-16 21:25:24

正如其他人提到的那样,在需要postcss-import插件之前,需要postwindcss v3。但是,从V4开始,此问题不再发生。

从tailwindcss v4开始

在v3中,tailwindcss软件包是邮政插件,但是在v4中,Postcss插件生活在专用的@tailwindcss/postcss/postcss 软件包中。

此外,在V4 Imports和供应商中,现在可以自动为您处理,因此您可以删除Postcss-importautoprefixer如果它们在您的项目中。

直到tailwindcss v3

预处理器提供的最有用的功能之一是能够将CSS组织到多个文件中,并通过处理@import提前在浏览器中进行处理,而不是在浏览器中进行组合。

用于使用PostCSS处理此操作的规范插件是Postcss-import

要使用它,请通过NPM安装插件:

  NPM安装-D PostCSS -Import
 

然后将其添加为PostCSS配置中的第一个插件:

  // Postcss.config.js
Module.exports = {
  插件:{
    'Postcss-import':{},
    parwindcss:{},
    AutoPrefixer:{},
  }
}
 

As others have mentioned, until TailwindCSS v3, the postcss-import plugin is required. However, from v4 onwards, this issue no longer occurs.

From TailwindCSS v4 onwards

In v3, the tailwindcss package was a PostCSS plugin, but in v4 the PostCSS plugin lives in a dedicated @tailwindcss/postcss package.

Additionally, in v4 imports and vendor prefixing is now handled for you automatically, so you can remove postcss-import and autoprefixer if they are in your project.

Until TailwindCSS v3

One of the most useful features preprocessors offer is the ability to organize your CSS into multiple files and combine them at build time by processing @import statements in advance, instead of in the browser.

The canonical plugin for handling this with PostCSS is postcss-import.

To use it, install the plugin via npm:

npm install -D postcss-import

Then add it as the very first plugin in your PostCSS configuration:

// postcss.config.js
module.exports = {
  plugins: {
    'postcss-import': {},
    tailwindcss: {},
    autoprefixer: {},
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文