laravel-mix purifyCss option not working

848 views Asked by At

im looking to use the purifyCss of laravel-mix. The fuction is working fine on a brand new installation but when i try to upgrade from an older version of laravel-mix nothing happens and no errors are shown.

this is the currect package.json file

{
  "private": true,
  "scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "cross-env": "^5.1",
    "laravel-mix": "^2.0",
    "popper.js": "^1.13.0",
    "purify-css": "^1.2.6",
    "purifycss-webpack": "^0.7.0"
  },
  "dependencies": {
    "bootstrap": "^4.0.0",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "normalize.css": "^8.0.0",
    "velocity-animate": "^2.0.1"
  }
}

this is my webpack.mix.js

let mix = require('laravel-mix');

mix.options({
    purifyCss: true
});

//default path
mix.setPublicPath('website');

//index
mix.sass('resources/assets/sass/index/index-desktop.scss', 'css/index/index-desktop.min.css');

and this is a test blade file

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ session('user.language_code') }}">
<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://fonts.googleapis.com/css?family=Caudex" rel="stylesheet">
    <link rel="stylesheet" href="{{ asset('css/index/index-desktop.min.css') }}">

</head>
<body>

</body>
</html>

Also im using yarn and when i try yarn run production the css is never removed.

2

There are 2 answers

1
SpyrosJevan On BEST ANSWER

The problem has been solved.

For anyone having the same problem check your class/id and be sure they dont have any numbers on it.

0
Alexandr On

There are more than accepted answer in this issue:

  1. Indeed there is an issue with class names. With no changes in the purifycss they should match /[a-z]+/
  2. The build may work for you with run dev, but fail while run prod because of the issue in the 3rd party repository (2nd level dependency) which strikes when you're purifying the minified css files, like bootstrap 4 for example. You can find detailed explanation in PR, and track the issue.

For now you can use npm install git://github.com/alex7r/css.git#master (yes, I do prefer npm)