相关疑难解决方法(0)

purgecss 无法识别条件类

所以我将 TailwindCSS 用于我正在开发的 WP 主题。

我在创建生产级主题文件时遇到了一个问题,因为根据我对问题的理解,purgecss 无法识别模板部件上使用的条件类。例如,假设我创建了一个名为“business-card.php”的模板部分,我在其中传递了一个变量type(使用set_query_var/ get_query_var):

页面-about.php

set_query_var('type', 'A');
get_template_part('template-parts/content/business', 'card');

set_query_var('type', 'B');
get_template_part('template-parts/content/business', 'card');
Run Code Online (Sandbox Code Playgroud)

企业卡.php

$type = get_query_var('type')
<div class="<?php echo type == 'A' ? 'text-color-A' : 'text-color-B' ?>">
--- insert some content here ---
</div>
Run Code Online (Sandbox Code Playgroud)

所以会有两个 div,一个有一个text-color-A类,另一个有一个text-color-B,两者都是使用配置文件创建的(而不是包含在基本的顺风主题中)。这在开发中很好——因为 tailwind 实际上从配置文件创建了实用程序颜色类。但是出于某种原因,当它在生产中(即清除和缩小)时,它没有那些实用程序类——它们只在模板部分作为条件类使用(而不是在任何其他文件中)。

wordpress-theming tailwind-css css-purge

4
推荐指数
3
解决办法
4586
查看次数