-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
33 lines (28 loc) · 911 Bytes
/
index.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
const path = require('path')
const critical = require('critical')
class CriticalCssWebpackPlugin {
constructor (options) {
this.options = Object.assign({
src: 'index.html',
inline: true,
width: 375,
height: 565,
target: 'index.html',
extract: true
}, options)
}
emit (compilation, callback) {
const css = Object.keys(compilation.assets)
.filter(function (filename) { return /\.css$/.test(filename) })
.map(function (filename) { return path.join(compilation.outputOptions.path, filename) })
critical.generate(Object.assign({ css, base: compilation.outputOptions.path }, this.options), (err) => {
callback(err)
})
}
apply (compiler) {
compiler.hooks.afterEmit.tapAsync('CriticalCssWebpackPlugin', (compilation, callback) => {
this.emit(compilation, callback)
})
}
}
module.exports = CriticalCssWebpackPlugin