So, there is this npm package Google suggests to generate critical CSS:
var critical = require('critical');
gulp.task('critical', function (cb) {
critical.generate({
base: 'app/',
src: 'index.html',
dest: 'css/index.css'
});
});
It is actually an awesome tool which works like a charm. The only disadvantage is that it only works for a single file in Gulp as opposed to other tasks that can be called with gulp.src('app/*.html')
for all matching files.
So I decided to list all my pages in an array and iterate through them:
var pages = ['index', 'pricing'];
gulp.task('critical', function (cb) {
for (var i = 0; i < pages.length; i++) {
critical.generate({
base: 'app/',
src: pages[i] + '.html',
dest: 'css/' + pages[i] + '.css'
});
}
});
which proved to be a working solution too (except some node.js memory issues).
The problem now is that I have to list the pages manually in the array. So I wonder if there is a way to generate such a list automatically with a function similar to gulp.src('app/*.html')
e.g. to include all .html pages from a selected folder to generate critical CSS for?
Any help would be greatly appreciated!