4

My application is using dust template, HTML template and also javascript to build the view. I have lot of code in javascript which add/remove the css class based on the business logic. Also this application is quite old therefore I wanted to get rid of all unused css code.

I tried to use gulp-uncss (https://www.npmjs.com/package/gulp-uncss) however its only accepting .html file as look up. Its not accepting .dust or .js files for lookup and due to that lot of used css class is also getting dropped.

Is there any open source tool/library which can be used to get rid of unused css by looking into html, js or dust files.

Cœur
  • 37,241
  • 25
  • 195
  • 267
joy
  • 3,669
  • 7
  • 38
  • 73
  • I highly doubt this is possible, how would you would know what to look for in the js? Some possible options: 1. Manually add the classes that are being used from other sources to the uncss options. 2. Run uncss after the js has been executed. Of course this won't work if you have any classes that are added after runtime. – joshhunt Jun 15 '15 at 01:28
  • humm...thanks for sharing your thoughts. – joy Jun 15 '15 at 02:53

1 Answers1

0

You can run your application on local web server and point the html property of uncss to that localhost URL:

var gulp = require('gulp');
var uncss = require('gulp-uncss');

gulp.task('default', function() {
    return gulp.src('site.css')
        .pipe(uncss({
            html: ['http://localhost:3000/']
        }))
        .pipe(gulp.dest('./out'));
});

Source: https://github.com/ben-eb/gulp-uncss/issues/28

CroModder
  • 27
  • 7