mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-16 21:39:29 -07:00
Exploring ways to preserve the vanilla JS browser demo without compromising on the bundle. Experimenting with embedding images in the bundle as data URIs
This commit is contained in:
20
js/fetchLibraries.js
Normal file
20
js/fetchLibraries.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export default async () => {
|
||||
let glMatrix, createREGL;
|
||||
|
||||
try {
|
||||
glMatrix = await import("gl-matrix");
|
||||
createREGL = (await import("regl")).default;
|
||||
} catch {
|
||||
const loadJS = (src) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const tag = document.createElement("script");
|
||||
[tag.onload, tag.onerror, tag.src] = [resolve, reject, src];
|
||||
document.body.appendChild(tag);
|
||||
});
|
||||
await Promise.all([loadJS("lib/regl.min.js"), loadJS("lib/gl-matrix.js")]);
|
||||
glMatrix = globalThis.glMatrix;
|
||||
createREGL = globalThis.createREGL;
|
||||
}
|
||||
|
||||
return { glMatrix, createREGL };
|
||||
};
|
||||
Reference in New Issue
Block a user