/
index.js
36 lines (31 loc) · 1.25 KB
/
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
34
35
36
import './initial.css';
const handleError = (err) => {
document.querySelector(".errors").textContent += `\n${err.toString()}`;
console.error(err);
}
const makeButton = (className, fn) => {
const button = document.querySelector(className);
button.addEventListener("click", () => {
button.disabled = true;
fn().then(() => {
button.disabled = false;
}).catch(handleError);
});
}
makeButton(".lazy-button", () => import('./lazy.js'));
makeButton(".lazy-button2", () => import('./lazy2.css'));
makeButton(".preloaded-button1", () => import(/* webpackChunkName: "preloaded1" */ './preloaded1'));
makeButton(".preloaded-button2", () => import(/* webpackChunkName: "preloaded2" */ './preloaded2'));
makeButton(".crossorigin", () => {
const originalPublicPath = __webpack_public_path__;
__webpack_public_path__ = "http://0.0.0.0:8080/dist/";
const promise = import("./crossorigin").then(() => {
const lastTwoElements = Array.from(document.head.children).slice(-2);
const hasCrossorigin = lastTwoElements.every(element => element.crossOrigin === "anonymous");
if (!hasCrossorigin) {
throw new Error('Chunks lost crossorigin="anonymous" attribute.')
}
});
__webpack_public_path__ = originalPublicPath;
return promise;
});