spatie / laravel-mix-purgecss

Zero-config Purgecss for Laravel Mix
https://spatie.be/en/opensource
MIT License
874 stars 38 forks source link

No content provided. #71

Closed chrisvidal closed 4 years ago

chrisvidal commented 5 years ago

Context with tailwindcss laravel mix inside October CMS (A laravel CMS based)

not sure about what config should be applied: my feils are dispersed in different folder like layout, pages, partials, ...

mix.setPublicPath('./assets/public/')
    .js('assets/js/app.js', 'js')
    .sass('assets/sass/app.scss', 'css')
    .tailwind()
    .purgeCss({
        enabled: true,
        extensions: ['htm', 'html', 'js', 'php', 'vue'],        
        folders: ['.'],
    });
chrisvidal commented 5 years ago

same error with this config

.purgeCss({
  content: [
            './**/*.htm',
            './**/*.html',
            './**/*.vue',
            './**/*.jsx',
        ],
});
KevinBeckers commented 5 years ago

Same error. Also using tailwind.

KevinBeckers commented 5 years ago

Solved my problem by specifying the template folder in folders.

Gummibeer commented 5 years ago

It seems like the content key isn't passed or overridden and you should use globs and folders config to set this.

spatie-bot commented 4 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

damsfx commented 4 years ago

Solved my problem by specifying the template folder in folders.

@KevinBeckers Hi,

I'm still dealing with some errors for this config. Can you provide an excerpt of your mix.config file?
Thank's.

KevinBeckers commented 4 years ago

Hello @damsfx,

This is what my purgeCss looks like:

.purgeCss({
  enabled: true,
  folders: ['./templates'],
  extensions: ['.twig', 'twig', 'html']
}
damsfx commented 4 years ago

Thank's @KevinBeckers ,

I've found a workaround this way :

/*
| Mix Asset Management
*/
    mix
        .setPublicPath('/')
        .setResourceRoot('/themes/mytheme/')
        .js(...)
        .sass(...)
        ...

/*
 | Purge
 */
    if (mix.inProduction()) {
        mix
            .purgeCss({
                content: [
                    'content/**/*.htm',
                    'layouts/**/*.htm',
                    'pages/**/*.htm',
                    'partials/**/*.htm',
                ],
                extractors: [
                    {
                        extractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || [],
                        // Specify the file extensions to include when scanning for class names.
                        extensions: ["html", "htm", "md", "js", "php", "vue"]
                    }
                ],
                // To be adapted to your needs
                whitelistPatterns:  [
                    /-active$/,
                    /-enter$/,
                    /show$/,
                    /scrolled$/
                ]
            })
    }

My mix process include the two directives setPublicPath and setResourceRoot to specifiy where to work.
This combianisaon gives me correct results for the objective to be reached.