我试图从一个或多个sass文件中删除未使用的css规则。
研究让我使用postcss-uncss作为删除未使用css的最佳选择,如果您不使用服务器端呈现(请参阅:https://www.purgecss.com/comparison)。
https://github.com/uncss/postcss-uncss
现在,postcss-uncss是uncss:https://github.com/uncss/uncss的包装器,然而,uncss文档让我感到困惑,这里的示例配置没有用:https://github.com/uncss/postcss-uncss#example-configuration。
如何为Laravel混合配置后置?
到目前为止,我拥有的是THis:
mix.js('resources/js/app.js', 'public/js')
.options({
processCssUrls: false,
postCss: [
require('postcss-uncss'),
tailwindcss('./tailwind.config.js')
],
})我想:
我将非常感激你的想法。
发布于 2019-07-02 16:29:43
这就是我最后所做的事情(根据我和亚当·瓦桑的谈话,这是一个比uncss更好的选择。)
let mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');
// Removes unused CSS
// According to Discord chat: Running Purge CSS as part of Post CSS is a ton faster than laravel-mix-purgecss
// But if that doesn't work use https://github.com/spatie/laravel-mix-purgecss
const purgecss = require('@fullhuman/postcss-purgecss')({
// Specify the paths to all of the template files in your project
content: [
'./resources/views/*.php',
'./resources/views/**/*.php',
'./resources/js/components/*.vue',
'./resources/js/components/**/*.vue',
],
// Include any special characters you're using in this regular expression
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || []
});
mix.options({
clearConsole: true, // in watch mode, clears console after every build
processCssUrls: false,
postCss: [
//require('tailwindcss'),
tailwindcss('./tailwind.config.js'),
// to enable purgecss on production only
...process.env.NODE_ENV === 'production' ? [purgecss] : []
// to enable on all environments, local and production
//purgecss
],
})
;发布于 2019-07-02 06:47:53
也许你可以试试空间套餐
让我们安装它。
npm i laravel-mix-purgecss在您的purgeCss中调用webpack.mix.js ()。
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.purgeCss({ enabled: true });https://stackoverflow.com/questions/56568348
复制相似问题