@@ -9,22 +9,34 @@ import type { ModuleLoader, GetResolver } from './types';
99
1010/**
1111 * create module loader
12- * @param options options
13- * @param options.resolver remote module resolver, default to umd resolver
14- * @param options.container container to append script, default is append to body in client side
1512 */
1613export function createLoader < Props extends Record < string , any > = any , Context = any > (
1714 options : {
15+ /**
16+ * remote module resolver, default to umd resolver
17+ */
1818 resolver ?: GetResolver < Context > ;
19+ /**
20+ * container to append script, default is append to body in client side
21+ */
1922 container ?: string | ( ( proxy : Context ) => Element ) ;
23+ /**
24+ * global variables to expose to remote module
25+ */
26+ globals ?: Record < string , any > ;
2027 } = { } ,
2128) {
22- // Set global VueDemi
23- if ( window && ! window . VueDemi ) {
24- window . VueDemi = VueDemi ;
29+ const _resolver = options . resolver ?.( options . container ) ?? ( getUmdResolver ( options . container as any ) as any ) ;
30+
31+ // Set global variables
32+ const proxy = _resolver . context ;
33+ if ( ! proxy . VueDemi ) {
34+ proxy . VueDemi = VueDemi ;
35+ }
36+ if ( options . globals ) {
37+ Object . assign ( proxy , options . globals ) ;
2538 }
2639
27- const _resolver = options . resolver ?.( options . container ) ?? ( getUmdResolver ( options . container as any ) as any ) ;
2840 const loader : ModuleLoader < Props , Context > = VueDemi . markRaw ( {
2941 install ( app ) {
3042 // this allows calling registerSubModules() outside of a component setup after
0 commit comments