在 Laravel 8 / Tailwind CSS v2.1 应用程序中,我制作了不同的布局。所以在`webpack.mix.js 中,我定义了自定义类文件。
const mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/backend.css', 'public/css', [
require("tailwindcss"),
])
.postCss('resources/css/profile.css', 'public/css', [
require("tailwindcss"),
])
.options({
processCssUrls: false,
postCss: [tailwindcss('./tailwind.config.js')],
});
任何*.css
文件都有独特的类,但它们都有一些共同的类。我想app.css
用一些共同的定义来定义一些共同点,并在backend.css
定义中说:
.admin_main_color {
@apply text-gray-300 bg-green-900;
}
修改: 因为那是 laravel 项目,我没有 HTML 文件,但有 Blade.php 文件。所以我尝试下一步: 在 webpack.mix.js 我添加了 app.css :
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
require("tailwindcss"),
])
.postCss('resources/css/backend.css', 'public/css', [
require("tailwindcss"),
])
.postCss('resources/css/profile.css', 'public/css', [
require("tailwindcss"),
])
.options({
processCssUrls: false,
postCss: [tailwindcss('./tailwind.config.js')],
});
在 resources/views/layouts/backend.blade.php 我添加了 app.css(在 backend.css 之前):
<title id="app_title">{{ config('app.name', 'Laravel') }}</title>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link href="{{ asset('css/backend.css') }}" rel="stylesheet">
在 resources/css/app.css 我有:
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
.app_main_color { // in some cases I need to possibility to overwrite class in frontend.css/backend.css
@apply text-yellow-300 bg-red-900;
}
但是当我尝试在 resources/css/backend.css :
@tailwind base;
@tailwind components;
@tailwind utilities;
@import app.css;
@layer base {
.test_class {
@apply text-gray-300 bg-red-800;
}
/*.app_main_color {*/
/* @apply text-gray-300 bg-green-900;*/
/*}*/
如果要在上面留下评论 3 行,我在控制台中收到错误:
(23:31) /mnt/_work_sdb8/wwwroot/lar/tAdsBack/resources/css/backend.css The `app_main_color` class does not exist. If you're sure that `app_main_color` exists, make sure that any `@import` statements are being properly processed before Tailwind CSS sees your CSS, as `@apply` can only be used for classes in the same CSS tree.
与 :
@import app.css;
没有帮助。我该怎么做?我希望我清楚地解释了我想要什么......
这将覆盖我能做到这一点,以及如何做到这一点admin_main_color
中的定义吗?app.css.
修改2: 在带有引导程序的laravel5-7中,我有定义变量的文件resources/sass/_variables.scss,在文件resources/sass/app.scss中我有行:
@import "node_modules/font-awesome/scss/font-awesome";
@import 'variables';
我可以在我的应用程序中使用类似的方式吗?如果是,如何?
修改3:
@import app_main_color;
/*@import app_main_color from app.css;*/
@layer base {
h3 {
@apply text-xl font-bold;
padding:4px;
}
h4 {
@apply text-lg font-bold;
padding:3px;
}
/*.app_main_color {*/
/* @apply text-gray-300 bg-green-900;*/
/*}*/
.admin_page_container_wrapper {
@apply flex-1 justify-items-start justify-self-start app_main_color p-1 m-0;
}
但我得到了错误:
(35:62) /mnt/_work_sdb8/wwwroot/lar/tAdsBack/resources/css/backend.css The `app_main_color` class does not exist. If you're sure that `app_main_color` exists, make sure that any `@import` statements are being properly processed before Tailwind CSS sees your CSS, as `@apply` can only be used for classes in the same CSS tree.
33 |
34 | .admin_page_container_wrapper {
> 35 | @apply flex-1 justify-items-start justify-self-start app_main_color p-1 m-0;
| ^
36 | }
导入 app_main_color 的感觉是它在其他类中使用,例如在 admin_page_container_wrapper 类的定义中,但我找不到如何制作它。