我在使用自定义CSS以及某些第三方库的现有应用程序中安装了TailwindCSS和PurgeCSS。我将PurgeCSS配置为仅清除单个顺风文件,但是由于某种原因,它从第三方库中删除了CSS选择器,也许我的配置是错误的:
webpack.mix.js
const mix = require("laravel-mix");
const purgeCss = require("@fullhuman/postcss-purgecss")
const tailwindCss = require("tailwindcss")
mix.webpackConfig(require("./webpack.parts"));
// Don't want to purge anything under app.scss, it contains custom css &
// current app related stuff
mix.sass("resources/sass/app.scss", "public/css").version();
// I simply want to add tailwind so I can use it in addition to whatever
// css the app currently uses
mix.postCss("resources/sass/tailwind.pcss", "public/css", [
tailwindCss,
...process.env.NODE_ENV === "production" ? [purgeCss(
{
content: [
"./resources/**/*.js",
"./resources/**/*.blade.php",
],
css: [
"./public/css/tailwind.css"
]
}
)] : []
])
尝试将css
的路径从./public/css/tailwind.css
更改为./resources/sass/tailwind.pcss
,但没有帮助
编辑:
似乎我不得不从app.scss
中移出一些依赖项才能使其正常工作,尽管我不确定为什么:
在mix.sass(app.scss)
之前添加了此代码段
mix.styles(
[
"./node_modules/datatables.net-bs4/css/dataTables.bootstrap4.css",
"./node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.standalone.css",
"./node_modules/animate.css/animate.css",
"./node_modules/react-datepicker/dist/react-datepicker.css",
],
"public/css/vendors.css"
).version()
答案 0 :(得分:2)
我无法重现您的错误,此代码对我来说是完美的。
const mix = require('laravel-mix');
const purgecss = require('@fullhuman/postcss-purgecss')({
content: [
'resources/**/*.blade.php',
],
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || []
})
mix.sass('resources/sass/app.scss', 'public/css').version();
mix.postCss('resources/sass/tailwind.pcss', 'public/css', [
require('tailwindcss'),
...process.env.NODE_ENV === 'production'
? [purgecss]
: []
])