-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-html-transform.js
41 lines (39 loc) · 1.21 KB
/
index-html-transform.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
module.exports = (targetOptions, indexHtml) => {
let newIndexHtml = indexHtml;
// Cordova index management
if (
targetOptions &&
targetOptions.configuration?.includes('cordova-production')
) {
const i = newIndexHtml.indexOf('</head>');
/**
* https://github.com/angular/angular/issues/22509
* Prevent cordova.js 5.2.4+ routing bug
**/
const cordovaScripts = `
<script>
if (/^app/.test(location.host)) {
window.addEventListener = function () {
EventTarget.prototype.addEventListener.apply(this, arguments);
};
window.removeEventListener = function () {
EventTarget.prototype.removeEventListener.apply(this, arguments);
};
document.addEventListener = function () {
EventTarget.prototype.addEventListener.apply(this, arguments);
};
document.removeEventListener = function () {
EventTarget.prototype.removeEventListener.apply(this, arguments);
};
document.write('<script src="cordova.js"><\\/script>');
}
</script>
`;
newIndexHtml = `
${newIndexHtml.slice(0, i)}
${cordovaScripts}
${newIndexHtml.slice(i)}
`;
}
return newIndexHtml;
};