Purgecss: error when running webpack build

Created on 20 Nov 2017  路  4Comments  路  Source: FullHuman/purgecss

am following this gist guide to use purgecss along with laravel, but for some reason each time i try to run yarn watch i get the error

92% recording/Users/novo/Public/five/node_modules/purgecss/lib/purgecss.js:1
(function (exports, require, module, __filename, __dirname) { "use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function normalizeArray(t,e){for(var r=0,n=t.length-1;n>=0;n--){var i=t[n];"."===i?t.splice(n,1):".."===i?(t.splice(n,1),r++):r&&(t.splice(n,1),r--)}if(e)for(;r--;r)t.unshift("..");return t}function resolve(){for(var t="",e=!1,r=arguments.length-1;r>=-1&&!e;r--){var n=r>=0?arguments[r]:"/";if("string"!=typeof n)throw new TypeError("Arguments to path.resolve must be strings");n&&(t=n+"/"+t,e="/"===n.charAt(0))}return t=normalizeArray(filter(t.split("/"),function(t){return!!t}),!e).join("/"),(e?"/":"")+t||"."}function normalize(t){var e=isAbsolute(t),r="/"===substr(t,-1);return(t=normalizeArray(filter(t.split("/"),function(t){return!!t}),!e).join("/"))||e||(t="."),t&&r&&(t+="/"),(e?"/":"")+t}function isAbsolute(t){return"/"===t.charAt(0)}function join(){return normalize(filter(

Error: The extractor has failed to extract the selectors.
    at t.value (/Users/novo/Public/five/node_modules/purgecss/lib/purgecss.js:1:89301)
    at t.value (/Users/novo/Public/five/node_modules/purgecss/lib/purgecss.js:1:88744)
    at t.value (/Users/novo/Public/five/node_modules/purgecss/lib/purgecss.js:1:87941)
    at /Users/novo/Public/five/node_modules/purgecss-webpack-plugin/lib/purgecss-webpack-plugin.js:199:83
    at Array.forEach (<anonymous>)
    at /Users/novo/Public/five/node_modules/purgecss-webpack-plugin/lib/purgecss-webpack-plugin.js:182:27
    at Array.forEach (<anonymous>)
    at Compilation.<anonymous> (/Users/novo/Public/five/node_modules/purgecss-webpack-plugin/lib/purgecss-webpack-plugin.js:174:30)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:204:14)
    at Compilation.<anonymous> (/Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:275:11)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:204:14)
    at Compilation.<anonymous> (/Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:275:11)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:204:14)
    at Compilation.<anonymous> (/Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:275:11)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:204:14)
    at Compilation.<anonymous> (/Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:275:11)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:204:14)
    at Compilation.<anonymous> (/Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:275:11)
    at Compilation.applyPluginsAsyncSeries (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:206:13)
    at sealPart2 (/Users/novo/Public/five/node_modules/webpack/lib/Compilation.js:662:9)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:202:11)
    at Compilation.compilation.plugin (/Users/novo/Public/five/node_modules/webpack/lib/ProgressPlugin.js:111:6)
    at next (/Users/novo/Public/five/node_modules/tapable/lib/Tapable.js:204:14)
    at /Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:244:13
    at /Users/novo/Public/five/node_modules/async/dist/async.js:473:16
    at iteratorCallback (/Users/novo/Public/five/node_modules/async/dist/async.js:1050:13)
    at /Users/novo/Public/five/node_modules/async/dist/async.js:958:16
    at /Users/novo/Public/five/node_modules/extract-text-webpack-plugin/dist/index.js:227:15
    at /Users/novo/Public/five/node_modules/async/dist/async.js:473:16
    at iteratorCallback (/Users/novo/Public/five/node_modules/async/dist/async.js:1050:13)
error Command failed with exit code 1.

and here is my current config

const mix = require('laravel-mix')
const glob = require('glob-all')
const purgeCss = require('purgecss-webpack-plugin')

mix.webpackConfig({
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env', 'stage-3']
                    }
                }
            }
        ]
    }
    plugins: [
        new purgeCss({
            paths: glob.sync([
                path.join(__dirname, 'resources/views/**/*.blade.php'),
                path.join(__dirname, 'resources/assets/js/**/*.vue'),
                path.join(__dirname, 'resources/assets/vendor/**/*.vue')
            ]),
            extractors: [
                {
                    extractor: class {
                        static extract(content) {
                            return content.match(/[A-z0-9-:\/]+/g)
                        }
                    },
                    extensions: ['html', 'js', 'php', 'vue']
                }
            ]
        })
    ]
})

am using purgecss-webpack-plugin: 0.11.0.

not sure what exactly is causing this but if you need any extra info plz do tell me 馃憤

Most helpful comment

This error happened when the extractor returns null. You can try the configuration below, it will return an empty array instead of null if no selectors is found:

       new purgeCss({
            paths: glob.sync([
                path.join(__dirname, 'resources/views/**/*.blade.php'),
                path.join(__dirname, 'resources/assets/js/**/*.vue'),
                path.join(__dirname, 'resources/assets/vendor/**/*.vue')
            ]),
            extractors: [
                {
                    extractor: class {
                        static extract(content) {
                            return content.match(/[A-z0-9-:\/]+/g) || []
                        }
                    },
                    extensions: ['html', 'js', 'php', 'vue']
                }
            ]
        })

All 4 comments

This error happened when the extractor returns null. You can try the configuration below, it will return an empty array instead of null if no selectors is found:

       new purgeCss({
            paths: glob.sync([
                path.join(__dirname, 'resources/views/**/*.blade.php'),
                path.join(__dirname, 'resources/assets/js/**/*.vue'),
                path.join(__dirname, 'resources/assets/vendor/**/*.vue')
            ]),
            extractors: [
                {
                    extractor: class {
                        static extract(content) {
                            return content.match(/[A-z0-9-:\/]+/g) || []
                        }
                    },
                    extensions: ['html', 'js', 'php', 'vue']
                }
            ]
        })

focken awesome, many thanx

I'm surprised @Ffloriel 's extractor isn't the default behavior. (Perhaps there is a good reason to return null and therefore cause an error when nothing is is found. I just can't think of one.)

podobno cie stary bil kurwo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pab89 picture Pab89  路  8Comments

TomS- picture TomS-  路  3Comments

joneldiablo picture joneldiablo  路  6Comments

crazy4groovy picture crazy4groovy  路  7Comments

spaceemotion picture spaceemotion  路  4Comments