diff --git a/packages/dom/index.ts b/packages/dom/index.ts index b0067eb..1f627fd 100644 --- a/packages/dom/index.ts +++ b/packages/dom/index.ts @@ -48,7 +48,10 @@ export function loadStyleSheet(source: string): Promise { } /** Load script */ -export function loadScript(source: string): Promise { +export function loadScript( + source: string, + attributes: Record = {} +): Promise { globalThis[REGISTRY][source] ??= new Promise( (resolve, reject) => { const script = document.createElement('script') @@ -57,6 +60,12 @@ export function loadScript(source: string): Promise { script.async = true script.type = 'text/javascript' + if (attributes) { + Object.entries(attributes).forEach(([name, value]) => { + script.setAttribute(name, value) + }) + } + script.onload = () => { resolve(script) }