(name: string)
| 2 | const features: Record<string, string | (() => Promise<any>)> = {}; |
| 3 | const host = UiContext.cdn_dynamic ? UiContext.cdn_prefix : '/'; |
| 4 | export default async function load(name: string) { |
| 5 | if (name === 'echarts') return import('echarts'); |
| 6 | if (name === 'moment') return import('moment'); |
| 7 | if (!window.lazyloadMetadata?.[`${name}.lazy.js`]) throw new Error(`Module ${name} not found`); |
| 8 | if (lazyModules[name]) return lazyModules[name]; |
| 9 | const tag = document.createElement('script'); |
| 10 | tag.src = `${host}lazy/${window.lazyloadMetadata[`${name}.lazy.js`]}/${name}.lazy.js`; |
| 11 | console.log('loading module: ', name); |
| 12 | lazyModules[name] = new Promise((resolve, reject) => { |
| 13 | tag.onerror = reject; |
| 14 | const timeout = setTimeout(reject, 30000); |
| 15 | window.lazyModuleResolver[name] = (item) => { |
| 16 | clearTimeout(timeout); |
| 17 | resolve(item); |
| 18 | }; |
| 19 | }); |
| 20 | document.body.appendChild(tag); |
| 21 | return lazyModules[name]; |
| 22 | } |
| 23 | |
| 24 | const val: Record<string, any> = {}; |
| 25 | /** @deprecated */ |
no test coverage detected