Skip to content
This repository has been archived by the owner on Dec 2, 2018. It is now read-only.

parse html recursively in folder #5

Closed
guillaumevincent opened this issue Mar 12, 2014 · 11 comments
Closed

parse html recursively in folder #5

guillaumevincent opened this issue Mar 12, 2014 · 11 comments

Comments

@guillaumevincent
Copy link

hi,
I have 62 templates in folders and subfolders
How can I specify to uncss to read all the html in a specific folder ?

this work:

gulp.task('uncss', function() {
    gulp.src('static/css/vendor/bootstrap.min.css')
        .pipe(uncss({
            html: ['templates/404.html','templates/contact/contact.html','templates/base.html' ]
        }))
        .pipe(gulp.dest('static/css'));
});

with a regex it doesn't:

gulp.task('uncss', function() {
    gulp.src('static/css/vendor/bootstrap.min.css')
        .pipe(uncss({
            html: ['templates/*.html', 'templates/*/*.html']
        }))
        .pipe(gulp.dest('static/css'));
});

Any idea ?

@ben-eb
Copy link
Owner

ben-eb commented Mar 12, 2014

The html option is passed straight through to UnCSS; I agree that this is a good feature, but you would be better off submitting it to the UnCSS issue tracker; that way other plugins that consume UnCSS (such as grunt-uncss), and UnCSS itself can benefit.

This plugin is just a streamy wrapper around the UnCSS module.

@ben-eb ben-eb closed this as completed Mar 12, 2014
@guillaumevincent
Copy link
Author

thank you ben-ed, I've submit a new feature > uncss/uncss#51

@giakki
Copy link

giakki commented Mar 17, 2014

Thanks for the suggestion, but it's probably better to implement at plugin-level. Doesn't gulp have a way to preprocess "star-paths" like grunt?

@ben-eb
Copy link
Owner

ben-eb commented Mar 17, 2014

Sure, both systems use minimatch. I suggested that this is probably better at the module level because then the other libraries that consume UnCSS can benefit and not just my wrapper; as of this writing:

  • broccoli-uncss
  • gulp-uncss
  • gulp-uncss-task
  • grunt-uncss
  • mimosa-uncss
  • uncss-brunch

Plus we don't know if there will be some other task in the future that will want this functionality.

@ben-eb
Copy link
Owner

ben-eb commented Mar 18, 2014

See also: uncss/grunt-uncss#64

@giakki
Copy link

giakki commented Mar 22, 2014

Wow, I didn't even imagine there were so many wrapper for uncss!
In that case, I'll get working on it, since it looks like it is a much requested feature and it is causing many headaches. 👍

@p-j
Copy link

p-j commented Apr 7, 2014

In the mean time, you can use glob.sync() which do exactly what you need here : take a glob pattern and turn it in an array of matched files.
It might also interest @giakki for the implementation upstream.

$ npm install glob --save-dev

var glob = require('glob');

gulp.task('uncss', function() {
    gulp.src('static/css/vendor/bootstrap.min.css')
        .pipe(uncss({
            html: glob.sync('templates/**/*.html')
        }))
        .pipe(gulp.dest('static/css'));
});

And if you need to glob multiple patterns, you can use lodash or underscore flatten to turn it in a single flat array of files.

Edit: I have here the very setup I'm talking about.

@jrdnbwmn
Copy link

@p-j That's awesome, thanks!

@drainpip
Copy link

@p-j just swinging by to thank you for the idea - works great :)

@p-j
Copy link

p-j commented Sep 26, 2014

Happy to help :)

@ben-eb I've seen you refer to my comment on several occasion, maybe adding a corresponding example in the readme could clear things up ?

@ben-eb
Copy link
Owner

ben-eb commented Sep 26, 2014

@p-j 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants