/
removeUnusedCss.js
40 lines (35 loc) · 1.04 KB
/
removeUnusedCss.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
const {comb} = require('email-comb')
const {get, merge} = require('lodash')
module.exports = async (html, config = {}) => {
if (get(config, 'removeUnusedCSS') === false) {
return html
}
const safelist = [
'*body*', // Gmail
'.gmail*', // Gmail
'.apple*', // Apple Mail
'.ios*', // Mail on iOS
'.ox-*', // Open-Xchange
'.outlook*', // Outlook.com
'.ogs*', // Outlook.com
'.bloop_container', // Airmail
'.Singleton', // Apple Mail 10
'.unused', // Notes 8
'.moz-text-html', // Thunderbird
'.mail-detail-content', // Comcast, Libero webmail
'*edo*', // Edison (all)
'#*', // Freenet uses #msgBody
'.lang*' // Fenced code blocks
]
const defaultOptions = {
backend: [
{heads: '{{', tails: '}}'},
{heads: '{%', tails: '%}'}
],
whitelist: [...get(config, 'whitelist', []), ...safelist]
}
const options = typeof config === 'boolean' && config ?
defaultOptions :
merge(defaultOptions, get(config, 'removeUnusedCSS', config))
return comb(html, options).result
}