-
Notifications
You must be signed in to change notification settings - Fork 771
/
client-load-module.ts
38 lines (36 loc) · 1.37 KB
/
client-load-module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type * as d from '../declarations';
import { BUILD } from '@app-data';
import { consoleError, consoleDevError } from './client-log';
export const cmpModules = /*@__PURE__*/ new Map<string, { [exportName: string]: d.ComponentConstructor }>();
export const loadModule = (
cmpMeta: d.ComponentRuntimeMeta,
hostRef: d.HostRef,
hmrVersionId?: string
): Promise<d.ComponentConstructor> | d.ComponentConstructor => {
// loadModuleImport
const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
const bundleId = cmpMeta.$lazyBundleId$;
if (BUILD.isDev && typeof bundleId !== 'string') {
consoleDevError(
`Trying to lazily load component <${cmpMeta.$tagName$}> with style mode "${hostRef.$modeName$}", but it does not exist.`
);
return undefined;
}
const module = !BUILD.hotModuleReplacement ? cmpModules.get(bundleId) : false;
if (module) {
return module[exportName];
}
/*!__STENCIL_STATIC_IMPORT_SWITCH__*/
return import(
/* @vite-ignore */
/* webpackInclude: /\.entry\.js$/ */
/* webpackExclude: /\.system\.entry\.js$/ */
/* webpackMode: "lazy" */
`./${bundleId}.entry.js${BUILD.hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : ''}`
).then((importedModule) => {
if (!BUILD.hotModuleReplacement) {
cmpModules.set(bundleId, importedModule);
}
return importedModule[exportName];
}, consoleError);
};