@@ -65,15 +65,15 @@ export async function generateEsmHosts(config: d.Config, compilerCtx: d.Compiler
6565
6666 const esmImports : EsmImport [ ] = Object . keys ( cmpRegistry ) . sort ( ) . map ( tagName => {
6767 const cmpMeta = cmpRegistry [ tagName ] ;
68- const data = JSON . stringify ( formatBrowserLoaderComponent ( cmpMeta ) ) ;
68+ const data = formatBrowserLoaderComponent ( cmpMeta ) ;
6969 return {
7070 name : dashToPascalCase ( tagName ) ,
7171 data,
7272 } ;
7373 } ) ;
7474
7575 const hosts = [
76- generateEsmLoader ( config , compilerCtx , outputTarget , esmImports ) ,
76+ generateEsmLoader ( config , compilerCtx , outputTarget ) ,
7777
7878 generateEsmHost ( config , compilerCtx , outputTarget , 'es2017' , esmImports ) ,
7979 ] ;
@@ -89,24 +89,20 @@ export async function generateEsmHosts(config: d.Config, compilerCtx: d.Compiler
8989export async function generateEsmHost ( config : d . Config , compilerCtx : d . CompilerCtx , outputTarget : d . OutputTargetDist , sourceTarget : d . SourceTarget , esmImports : EsmImport [ ] ) {
9090 await Promise . all ( [
9191 generateEsm ( config , compilerCtx , outputTarget , sourceTarget , esmImports ) ,
92- generateDefineCustomElements ( config , compilerCtx , outputTarget , sourceTarget , esmImports ) ,
92+ generateDefineCustomElements ( config , compilerCtx , outputTarget , sourceTarget ) ,
9393 ] ) ;
9494}
9595
96- async function generateDefineCustomElements ( config : d . Config , compilerCtx : d . CompilerCtx , outputTarget : d . OutputTargetDist , sourceTarget : d . SourceTarget , esmImports : EsmImport [ ] ) {
96+ async function generateDefineCustomElements ( config : d . Config , compilerCtx : d . CompilerCtx , outputTarget : d . OutputTargetDist , sourceTarget : d . SourceTarget ) {
9797 const componentsFileName = getComponentsEsmFileName ( config ) ;
98- const register = esmImports . map ( c => `c.${ c . name } ` ) . join ( ',\n ' ) ;
9998 const c = `
10099// ${ config . namespace } : Custom Elements Define Library, ES Module/${ sourceTarget } Target
101100
102101import { defineCustomElement } from './${ getCoreEsmFileName ( config ) } ';
103- import * as c from './${ componentsFileName } ';
104-
105- export * from './${ componentsFileName } ';
106- export { defineCustomElement };
102+ import { COMPONENTS } from './${ componentsFileName } ';
107103
108104export function defineCustomElements(win, opts) {
109- return defineCustomElement(win, [\n ${ register } \n ] , opts);
105+ return defineCustomElement(win, COMPONENTS , opts);
110106}
111107` ;
112108
@@ -118,15 +114,14 @@ async function generateEsm(config: d.Config, compilerCtx: d.CompilerCtx, outputT
118114 const VAR = sourceTarget === 'es5' ? 'var' : 'const' ;
119115 const indexContent = [
120116 `// ${ config . namespace } : Host Data, ES Module/${ sourceTarget } Target` ,
121-
122- ...esmImports . map ( ( { name, data} ) => `export ${ VAR } ${ name } = ${ data } ;` )
117+ `export ${ VAR } COMPONENTS = ${ JSON . stringify ( esmImports . map ( ( { data} ) => data ) ) } `
123118 ] . join ( '\n' ) ;
124119
125120 const componentsEsmFilePath = getComponentsEsmBuildPath ( config , outputTarget , sourceTarget ) ;
126121 await compilerCtx . fs . writeFile ( componentsEsmFilePath , indexContent ) ;
127122}
128123
129- async function generateEsmLoader ( config : d . Config , compilerCtx : d . CompilerCtx , outputTarget : d . OutputTargetDist , esmImports : EsmImport [ ] ) {
124+ async function generateEsmLoader ( config : d . Config , compilerCtx : d . CompilerCtx , outputTarget : d . OutputTargetDist ) {
130125 const loaderPath = getLoaderEsmPath ( config , outputTarget ) ;
131126 const es5EntryPoint = getDefineCustomElementsPath ( config , outputTarget , 'es5' ) ;
132127 const es2017EntryPoint = getDefineCustomElementsPath ( config , outputTarget , 'es2017' ) ;
@@ -139,7 +134,7 @@ async function generateEsmLoader(config: d.Config, compilerCtx: d.CompilerCtx, o
139134 } , null , 2 ) ;
140135
141136 const indexPath = config . buildEs5 ? es5EntryPoint : es2017EntryPoint ;
142- const indexDtsContent = generateIndexDts ( esmImports ) ;
137+ const indexDtsContent = generateIndexDts ( ) ;
143138 const indexContent = `export * from '${ normalizePath ( config . sys . path . relative ( loaderPath , indexPath ) ) } ';` ;
144139 const indexES2017Content = `export * from '${ normalizePath ( config . sys . path . relative ( loaderPath , es2017EntryPoint ) ) } ';` ;
145140
@@ -162,16 +157,11 @@ async function patchCollection(config: d.Config, compilerCtx: d.CompilerCtx, out
162157 await compilerCtx . fs . writeFile ( collectionInterfacePath , '' ) ;
163158}
164159
165- function generateIndexDts ( esmImports : EsmImport [ ] ) {
166- return [
167- 'export declare function defineCustomElements(win: Window, opts?: any): Promise<void>;' ,
168- 'export declare function defineCustomElement(win: Window, elements: any[], opts?: any): Promise<void>;' ,
169-
170- ...esmImports . map ( i => `export declare const ${ i . name } : any;` )
171- ] . join ( '\n' ) ;
160+ function generateIndexDts ( ) {
161+ return 'export declare function defineCustomElements(win: any, opts?: any): Promise<void>;' ;
172162}
173163
174164interface EsmImport {
175165 name : string ;
176- data : string ;
166+ data : any ;
177167}
0 commit comments