-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriticalCSS.js
55 lines (52 loc) · 1.03 KB
/
criticalCSS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var critical = require('critical')
var fg = require('fast-glob')
var htmlSources = fg.sync("dist/**/*.html")
console.log(htmlSources)
function startNewJob () {
const source = htmlSources.pop()
console.log(source)
if (!source) {
return Promise.resolve()
}
return critical.generate({
css: ['dist/_includes/css/main.css', 'dist/_includes/css/atelier-forest-light.css'],
inline: true,
src: source,
target: {
html: source
}
})
.then(()=>{
console.log("inline critical CSS for "+source+" succeed!")
return startNewJob()
})
.catch(err => {
console.log("inline critical CSS for "+source+" failed!")
console.log(err)
return startNewJob()
})
}
/*
htmlSources.forEach(function(item){
promises.push(critical.generate({
inline: true,
src: item,
target: {
html: item
}
}))
})
*/
Promise.all([
startNewJob(),
startNewJob(),
startNewJob(),
startNewJob(),
startNewJob()
])
.then(()=>{
console.log('all done!')
})
.catch(error => {
console.log(error)
})