gpt4 book ai didi

Micro-frontend in Angular 16 with Module Federation, HTML not loading in element(Angular 16中的微前端与模块联合,HTML未加载到元素中)

转载 作者:bug小助手 更新时间:2023-10-27 20:55:30 25 4
gpt4 key购买 nike



I created 2 Angular 16 projects, 1 host and 1 remote. I based my code on the MF Flight Tutorial
instead of having 1 Angular project I separated them into 2 projects the shell-ui (host) and the launch-ui (remote).

我创建了两个角度16项目,一个主机和一个远程。我的代码基于MF Flight教程,而不是一个角度项目,我将它们分成两个项目:Shell-UI(主机)和Launch-UI(远程)。


My problem is when I run both projects the launch-element does not load any data and it doesn't give me any errors. I also added the link to the React Version: ^17.0.1 from the FM tutorial and the data gets displayed.

我的问题是,当我同时运行这两个项目时,Launch-Element不会加载任何数据,也不会给我任何错误。我还添加了FM教程中REACT版本的链接:^17.0.1,数据就会显示出来。


Here is my route code (app.routes.ts) in the shell-ui project:

下面是我在shell-ui项目中的路由代码(app.routes.ts):


export const APP_ROUTES: Routes = [
{
path: '',
component: NotFoundComponent,
pathMatch: 'full',
},
{
path: 'launch',
component: WebComponentWrapper,
data: {
type: 'module',
remoteEntry:
'http://localhost:4202/remoteEntry.js',
remoteName: 'launch',
exposedModule: './launch',
elementName: 'launch-element',
} as WebComponentWrapperOptions,
},
{
path: 'react',
component: WebComponentWrapper,
data: {
type: 'script',
remoteEntry:
'https://witty-wave-0a695f710.azurestaticapps.net/remoteEntry.js',
remoteName: 'react',
exposedModule: './web-components',
elementName: 'react-element',
} as WebComponentWrapperOptions,
},

Here is my code in the launch-ui webpack.config.js file:

以下是我在Launch-UI webpack.config.js文件中的代码:


plugins: [
new ModuleFederationPlugin({
library: { type: "module" },

// For remotes (please adjust)
name: "launch",
filename: "remoteEntry.js",
exposes: {
'./launch': '/src/app/launch/launch.module.ts',
},

shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },

...sharedMappings.getDescriptors()
})

}),

Here is a screenshot of the launch-element with no data:
launch element screenshot

下面是没有数据的launch-element的屏幕截图:


Here is a screenshot of the react-element with data:
React element screen

以下是带数据的Reaction元素的屏幕截图:


I've also uploaded my code in Github
Github shell-ui
Github launch-ui

我还在Github Github shell-UI Github Launch-UI中上传了我的代码


更多回答
优秀答案推荐
更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com