2 回答

TA贡献1848条经验 获得超6个赞
在Purge 运行之前,您正在将 scss 编译为 css ,因此不需要只清除 main.css(或任何调用的输出)的 .scss 文件。
你编译的类名是否完整地存在于你的模板文件中?如果它们与模板中的类不是 100% 匹配,那么它们将非常正确地被清除。

TA贡献2080条经验 获得超4个赞
问题在于 WordPress 类没有包含在模板文件中,然后被清除。解决方案是切换到使用 UnCSS,这允许我设置 URLS 以供 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',
]
})] : [],
]
});
我还使用了 UnCSS exclude from purge CSS 注释:
/* uncss:ignore start */
my css goes here
/* uncss:ignore end */
我最终在我所有的自定义 sass 文件上使用了这个,除了 tailwind 文件,这样唯一被清除的选择器是 tailwind 实用程序,这为我节省了大约 300 KB。
添加回答
举报