purifycss / gulp-purifycss

Removed unused CSS with the gulp build tool
MIT License
336 stars 21 forks source link

Strange mismatch in selector name #16

Open aseem2625 opened 8 years ago

aseem2625 commented 8 years ago

Hi, I noticed a strange thing. Don't know if it's known.

My config

gulp.task('purifycss', function () {
    return gulp.src('src/bundle/css/**/*.css')
        .pipe(purify(['src/bundle/js/**/*.js', 'src/**/*.html']))
        .pipe(gulp.dest('src/bundle/css'))
});

This config works perfectly fine but strange results for following things.

Case: If I've 2 selectors in css file '.js-newClass' and '.newClass1' where only '.js-newClass' is being added through js and '.newClass1' is nowhere used. So purifycss still keeps '.newClass1' because of string matching 'newClass' in both selectors and '.js-newClass' is being kept because it's been used in js.
Observations:

  1. If I would remove '.js-newClass' from js then purifycss will remove both selectors from final css.
  2. If I would rename '.js-newClass' to '.js-newClas' or '.js-newClassa' then also it will remove '.newClass1' selector from the final css.
  3. If I would rename '.js-newClass' to '.js-newClass-hello' then also it keeps 'newClass1'
  4. If I would rename '.newClass1' to '.newClass' then also it still keep '.newClass' in the final css because 'newClass matches with '.js-newClass' substring
  5. If I would rename '.newClass1' to '.newClassa' then it removes it from final css because '.newClassa' is differently matches to '.js-newClass' than how '.newClass1' is matched to '.js-newClass'. So, putting number doesn't matter.

Please, let me know, whether it's know or can it be fixed with an update?

Thanks