Amd import svelte...

javascript

amd import svelte:
другие самплы
let lazyCache = {}

/**
 * 
 * @description:
 * ```amd
 * ```
 * @param {string} url 
 */
export function lazyComponent(url){

	function define(_, func) { 
		let obj ={}; 
		const r = (_ || func)(obj); 		
		return r || obj; 
	}

	const p  = new Promise(function(resolve, reject){

		let linkName = url.split('/').pop().split('.').shift()

		document.getElementById(linkName) || (function uploadLink(resolve) {
			let link = document.head.appendChild(document.createElement('link'))		
			link.href = staticPath + 'styles/' + linkName + '.css';
			link.rel="stylesheet";
			link.id = linkName;
	
			link.onload = () => {
				console.log('uploaded');	
			}
		})()
	
		if (lazyCache[url]) setTimeout(function() {
			resolve(lazyCache[url])
		}, 700)
		else fetch(url)
			.then(r => r.text())
			.then(v => {			
				const r = lazyCache[url] = globalThis['eval'](define.toString() + v)			
				resolve(r);
			})

	})



	// if (lazyCache[url]) return {then: (clb) => clb(lazyCache[url])}

	// const p = fetch(url)
	// 	.then(r => r.text())
	// 	.then(v => {			
	// 		const r = lazyCache[url] = globalThis['eval'](define.toString() + v)			
	// 		return r;
	// 	})	



	return p;
}
(ваш голос учтен)

Прикрепить файл