@@ -90,25 +90,29 @@ interface IBundle {
90
90
transform ?: string ;
91
91
}
92
92
93
- export function transformRoutesToBundle ( routes : IRoute [ ] , parent ?: IRoute ) : IBundle [ ] {
93
+ export function getBundleNameFrom ( component : string ) : string {
94
+ const bundleName = component . replace ( / ^ @ \/ / , '' ) . replace ( / \. [ t j ] s x ? $ / , '' ) ;
95
+ if ( bundleName === 'pages/index' ) {
96
+ return 'host' ;
97
+ }
98
+ return bundleName ;
99
+ }
100
+
101
+ export function transformRoutesToBundle ( routes : IRoute [ ] ) : IBundle [ ] {
94
102
const bundles : IBundle [ ] = [ ] ;
95
103
for ( const route of routes ) {
96
- if ( Array . isArray ( route . routes ) ) {
97
- bundles . push ( ...transformRoutesToBundle ( route . routes , route ) ) ;
98
- } else {
99
- if ( route . component ) {
100
- bundles . push ( {
101
- name : route . component ,
102
- entry :
103
- parent && parent . component
104
- ? { entryFiles : [ route . component ] , setupFiles : [ parent . component ] }
105
- : route . component ,
106
- dependsOn : [ 'index' ] ,
107
- app : true ,
108
- type : 'indexed-ram-bundle' ,
109
- transform : 'transform' ,
110
- } ) ;
111
- }
104
+ if ( route . component ) {
105
+ bundles . push ( {
106
+ name : getBundleNameFrom ( route . component ) ,
107
+ entry : route . component ,
108
+ dependsOn : [ 'index' ] ,
109
+ app : true ,
110
+ // type: 'indexed-ram-bundle',
111
+ transform : 'transform' ,
112
+ } ) ;
113
+ }
114
+ if ( Array . isArray ( route . routes ) && route . routes . length > 0 ) {
115
+ bundles . push ( ...transformRoutesToBundle ( route . routes ) ) ;
112
116
}
113
117
}
114
118
return bundles ;
@@ -185,14 +189,15 @@ export async function routesToJSON(api: IApi) {
185
189
if ( isFunctionComponent ( value ) ) return value ;
186
190
if ( api . config . dynamicImport ) {
187
191
const [ component ] = value . split ( SEPARATOR ) ;
192
+ const bundleName = getBundleNameFrom ( component ) ;
188
193
let loading = '' ;
189
194
if ( api . config . dynamicImport . loading ) {
190
195
loading = `,loading: require('${ api . config . dynamicImport . loading } ').default` ;
191
196
}
192
197
return `dynamic({
193
198
loader: async () => {
194
- await Multibundle.loadBundle('${ component } ');
195
- return Multibundle.getBundleExport('${ component } ');
199
+ await Multibundle.loadBundle('${ bundleName } ');
200
+ return Multibundle.getBundleExport('${ bundleName } ');
196
201
}${ loading } })` ;
197
202
} else {
198
203
return `require('${ value } ').default` ;
0 commit comments