forked from webpack-contrib/mini-css-extract-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 1.38 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
37
38
39
40
import './initial.css';
const handleError = (err) => {
document.querySelector(".errors").textContent += `\n${err.toString()}`;
console.error(err);
}
const makeButton = (className, fn, shouldDisable = true) => {
const button = document.querySelector(className);
button.addEventListener("click", () => {
if(shouldDisable) {
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(".lazy-failure-button", () => import('./lazy-failure.js'), false);
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 miss crossorigin="anonymous" attribute.')
}
});
__webpack_public_path__ = originalPublicPath;
return promise;
});