spatie / laravel-mix-purgecss

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

Ignore Select2 classes or identifer from being purged #129

Closed wcaaan closed 2 years ago

wcaaan commented 2 years ago

Hey, I have a select2 js file located here resources/assets/libs/select2/dist/js/select2.min.js. The select2.min.js file is included inside core.js file.

The css file css NOT scss is located here resources/assets/libs/select2/dist/css/select2.css. The select2.css file is included inside core.scss file.

When i don't use purgeCss the select2 classes injected by its JS are working fine but when i apply purgeCss the select2 classes injected by its JS are no longer there in the css and that is why select2 design is messed up.

I want to exlude all those classes OR ID's used in my blade views or JS.

Please tell me do i have to use all the levels of safelist ? or which one should i use in this case, i also tried path.join(__dirname, 'resources/**/*.blade.php')

const mix = require('laravel-mix');
require('laravel-mix-purgecss');
const path = require('path');

mix
  .js('resources/js/core/core.js', 'public/js')
  .js('resources/js/core/guest.js', 'public/js')
  .js('resources/js/core/dashboard.js', 'public/js')
  .js('resources/js/admin/application.js', 'public/js')
  .js('resources/js/core/datatableCore.js', 'public/js')

  .copyDirectory('resources/js/flasher', 'public/js', false)

  .sass('resources/css/core.scss', 'public/css')
  .sass('resources/css/guest.scss', 'public/css')
  .sass('resources/css/dashboard.scss', 'public/css')
  .sass('resources/css/minimal.scss', 'public/css')

  .copy('resources/assets/images/', 'public/images', false)

  .purgeCss({
  enabled: true,
  content: [
      path.join(__dirname, 'resources/**/*.php'),
      path.join(__dirname, 'resources/**/*.js'),
  ],
  safelist: {
      standard: ['select2', '/^select2-/', /select2/],
      deep: [/select2$/],
      greedy: [/select2$/],
  },
});