您要在清除运行之前将scss编译为css ,因此不必只清除main.css(或任何称为输出的内容)中的.scss文件。
您的已编译类名称实际上在模板文件中完全存在 吗?如果它们与模板中的类不是100%匹配,则将非常正确地清除它们。
,
问题在于WordPress类未包含在模板文件中,然后被清除。解决方案是切换到使用UnCSS,这使我可以设置URL以供UnCSS访问,并且不会清除这些页面上使用的任何类。我还包括一些标准的WordPress类,这些类在网上找到了清单。
我的最终配置是:
const uncss = require('postcss-uncss');
mix.js('js/dev/app.js','js/build/app.js')
.sass('css/dev/app.scss','css/build')
.options({
processCssUrls: false,postCss: [
tailwindcss('./tailwind.config.js'),...process.env.NODE_ENV === 'production' ? [uncss({
html: [
'./*.php','./template-parts/*.php','https://www.example.com','https://www.example.com/work/','https://www.example.com/work/example-project/','https://www.example.com/contact/','https://www.example.com/blog/','https://www.example.com/blog/laravel-php-framework/',],ignore: [
'.rtl','.home','.blog','.archive','.date','.error404','.logged-in','.admin-bar','.no-customize-support','.custom-background','.wp-custom-logo','.alignnone','.alignright','.alignleft','.wp-caption','.wp-caption-text','.screen-reader-text','.comment-list','.grecaptcha-badge',/^search(-.*)?$/,/^(.*)-template(-.*)?$/,/^(.*)?-?single(-.*)?$/,/^postid-(.*)?$/,/^attachmentid-(.*)?$/,/^attachment(-.*)?$/,/^page(-.*)?$/,/^(post-type-)?archive(-.*)?$/,/^author(-.*)?$/,/^category(-.*)?$/,/^tag(-.*)?$/,/^tax-(.*)?$/,/^term-(.*)?$/,/^(.*)?-?paged(-.*)?$/,'.animate','.animated','.bounce','.fadeInDown','.fadeIn','.fadeInUp','.jackInTheBox',]
})] : [],]
});
我还利用了从清除CSS注释中排除的UnCSS:
/* uncss:ignore start */
my css goes here
/* uncss:ignore end */
我最终在除风顺文件之外的所有自定义sass文件上使用了此文件,因此清除的唯一选择器是顺风实用程序,为我节省了约300 KB。
本文链接:https://www.f2er.com/3128489.html