diff --git a/scripts/scripts.js b/scripts/scripts.js index 533c05d..3eb23f1 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1,5 +1,3 @@ -import { setLibs } from './utils.js'; - const LIBS = '/libs'; const STYLES = ['/styles/styles.css']; const CONFIG = { @@ -157,6 +155,22 @@ const loadStyle = (path) => { eagerLoad(marquee.querySelector('img')); }()); +export const [setLibs, getLibs] = (() => { + let libs; + return [ + (prodLibs, location) => { + libs = (() => { + const { hostname, search } = location || window.location; + if (!(hostname.includes('.hlx.') || hostname.includes('local'))) return prodLibs; + const branch = new URLSearchParams(search).get('milolibs') || 'main'; + if (branch === 'local') return 'http://localhost:6456/libs'; + return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`; + })(); + return libs; + }, () => libs, + ]; +})(); + const miloLibs = setLibs(LIBS); (function loadStyles() {