spatie/laravel-mix-purgecss

Not working with tailwindcss (sass)

Closed this issue · 2 comments

Hello,
When I try to run npm run prod, I get the following error.

> @ prod D:\Sites\poll
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

D:\Sites\poll\node_modules\purgecss\lib\purgecss.js:379
            if (!options.content || !options.content.length) throw new Error(ERROR_MISSING_CONTENT);
                                                             ^

Error: No content provided.
    at Purgecss.checkOptions (D:\Sites\poll\node_modules\purgecss\lib\purgecss.js:379:68)
    at new Purgecss (D:\Sites\poll\node_modules\purgecss\lib\purgecss.js:346:14)
    at D:\Sites\poll\node_modules\purgecss-webpack-plugin\lib\purgecss-webpack-plugin.js:261:26
    at Array.forEach (<anonymous>)
    at D:\Sites\poll\node_modules\purgecss-webpack-plugin\lib\purgecss-webpack-plugin.js:231:23
    at Array.forEach (<anonymous>)
    at PurgecssPlugin.runPluginHook (D:\Sites\poll\node_modules\purgecss-webpack-plugin\lib\purgecss-webpack-plugin.js:219:26)
    at Compilation.<anonymous> (D:\Sites\poll\node_modules\purgecss-webpack-plugin\lib\purgecss-webpack-plugin.js:207:18)
    at next (D:\Sites\poll\node_modules\tapable\lib\Tapable.js:204:14)
    at Compilation.<anonymous> (D:\Sites\poll\node_modules\extract-text-webpack-plugin\dist\index.js:275:11)
    at Compilation.applyPluginsAsyncSeries (D:\Sites\poll\node_modules\tapable\lib\Tapable.js:206:13)
    at applyPluginsAsyncSeries (D:\Sites\poll\node_modules\webpack\lib\Compilation.js:665:9)
    at next (D:\Sites\poll\node_modules\tapable\lib\Tapable.js:202:11)
    at D:\Sites\poll\node_modules\extract-text-webpack-plugin\dist\index.js:244:13
    at D:\Sites\poll\node_modules\async\dist\async.js:473:16
    at iteratorCallback (D:\Sites\poll\node_modules\async\dist\async.js:1064:13)
    at D:\Sites\poll\node_modules\async\dist\async.js:969:16
    at D:\Sites\poll\node_modules\extract-text-webpack-plugin\dist\index.js:227:15
    at D:\Sites\poll\node_modules\async\dist\async.js:473:16
    at iteratorCallback (D:\Sites\poll\node_modules\async\dist\async.js:1064:13)
    at D:\Sites\poll\node_modules\async\dist\async.js:969:16
    at D:\Sites\poll\node_modules\extract-text-webpack-plugin\dist\index.js:216:21
    at rebuilding.forEach.cb (D:\Sites\poll\node_modules\webpack\lib\Compilation.js:534:29)
    at Array.forEach (<anonymous>)
    at callback (D:\Sites\poll\node_modules\webpack\lib\Compilation.js:534:15)
    at processModuleDependencies (D:\Sites\poll\node_modules\webpack\lib\Compilation.js:553:5)
    at process._tickCallback (internal/process/next_tick.js:61:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ prod: `cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

webpack.mix.js (laravel mix):

mix.js('web/js/app.js', 'js/')
    .sass('web/sass/app.scss', 'css/')
    .options({processCssUrls: false, postCss: [ tailwindcss('./tailwind.js') ],})
    .purgeCss();

Not sure, but I think this error pops up if you have an empty directory in the files that Purgecss scans for selectors.

I ran into this using it outside of Laravel, it seems it means that it can't find the files it is supposed to scan for selectors. so I needed to add the folder that holds my templates and the extension for those templates. In my case it looks like this:

.purgeCss({ folders: ['/assets/src/scss', 'templates/'], extensions: ['twig'] })