import type * as d from '../declarations' ; import { BUILD } from '@app-data' ; import { consoleError , consoleDevError } from './client-log' ; export const cmpModules = new Map < string , { [ exportName ] : d . ComponentConstructor ; } > ( ) ; export const loadModule = ( cmpMeta , hostRef , hmrVersionId ? ) : Promise < d . ComponentConstructor > | d . ComponentConstructor => { 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 ] ; } return import ( `./${ bundleId }.entry.js${ BUILD . hotModuleReplacement && hmrVersionId ? '?s-hmr=' + hmrVersionId : '' }` ) . then ( ( importedModule ) => { if ( ! BUILD . hotModuleReplacement ) { cmpModules . set ( bundleId , importedModule ) ; } return importedModule [ exportName ] ; } , consoleError ) ; } ;