-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfill.js
52 lines (45 loc) · 1.28 KB
/
polyfill.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
/*
* Add polyfills
*/
import defaultsDeep from 'lodash/defaultsDeep'
import { requireOnce } from '@cloak-app/utils'
export default function() {
// Get the list of polyfill keywords
const polyfills = this.options.cloak?.boilerplate?.polyfills || []
if (!polyfills.length) return
// Polyfills *not* provided by polyfill.io
const polyfillPackages = ['objectFit']
// Add polyfill.io polyfills
const polyfillIoKeywords = polyfills.filter(keyword => {
return !polyfillPackages.includes(keyword)
})
if (polyfillIoKeywords.length) {
this.options.head.script.push({
src: 'https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=' +
polyfillIoKeywords.join('%2C'),
hid: 'polyfill.io',
body: true,
})
}
// Add package based polyfills
const packagePolyfills = polyfills.filter(keyword => {
return polyfillPackages.includes(keyword)
})
if (packagePolyfills.length) {
// Setup options structure
defaultsDeep(this.options, {
polyfill: {
features: [],
}
})
// Add objectFit polyfill
if (packagePolyfills.includes('objectFit')) {
this.options.polyfill.features.push({
require: 'objectFitPolyfill',
detect: () => document.documentElement.style.objectFit != null
})
}
// Add the Nuxt Polyfill module
requireOnce(this, 'nuxt-polyfill')
}
}