How to use gulp-uncss to also look into javascript file and .dust templates

1.4k Views Asked by At

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.

1

There are 1 best solutions below

0
On

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