jjb-lc-designable
Version:
基于alibaba-designable源码二次封装的表单设计器。
36 lines (34 loc) • 1.06 kB
text/typescript
import { getNpmCDNRegistry } from '../registry'
import { globalThisPolyfill } from 'jjb-lc-designable/shared'
export interface ILoadScriptProps {
package: string
entry: string
root: string
base?: string
}
export const loadScript = async (props: ILoadScriptProps) => {
const options: ILoadScriptProps = {
base: getNpmCDNRegistry(),
...props,
}
if (globalThisPolyfill[props.root]) return globalThisPolyfill[options.root]
const path = `${options.base}/${options.package}/${options.entry}`
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.type = 'text/javascript'
script.async = false
script.src = path
script.onload = () => {
const module = globalThisPolyfill[options.root]
globalThisPolyfill['define'] = define
resolve(module)
script.remove()
}
script.onerror = (err) => {
reject(err)
}
const define = globalThisPolyfill['define']
globalThisPolyfill['define'] = undefined
document.body.appendChild(script)
})
}