spatie / laravel-mix-purgecss

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

Doesn't work with svg or jsx paths #33

Closed mxkxf closed 6 years ago

mxkxf commented 6 years ago

Hi,

The plugin works great with .html files but when I try to add svg or jsx files to the globs:

require('dotenv').config();
require('laravel-mix-purgecss');

const mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');

mix.setPublicPath('public')
    .react('assets/js/app.jsx', 'public/build/js')
    .postCss('assets/css/app.css', 'public/build/css', [
        tailwindcss('./tailwind.config.js'),
    ])
    .version()
    .browserSync(process.env.APP_URL)
    .purgeCss({
        enabled: mix.inProduction(),
        globs: [
            path.join(__dirname, 'templates/**/*.html'),
            path.join(__dirname, 'templates/**/*.svg'),
            path.join(__dirname, 'assets/js/**/*.jsx'),
        ],
        extensions: ['html', 'js', 'php', 'vue'],
    });

I get the following error:

/Users/mikefrancis/Code/craft-starter-kit/node_modules/purgecss/lib/purgecss.js:674
                        throw _iteratorError5;
                        ^

TypeError: Cannot read property 'extractor' of undefined

Is this fixable or am I doing something wrong?

mxkxf commented 6 years ago

Ah, I am an idiot - I need to add the extensions to the config:

mix.purgeCss({
        // ...
        extensions: ['html', 'js', 'php', 'vue', 'jsx', 'svg'],
    });

Hope this helps someone in the future!