【发布时间】:2021-08-09 03:32:52
【问题描述】:
我在 MonoRepo 中有两个 Angular 应用,一个外壳应用和一个内容应用。 shell 应用就像一个显示卡片的登陆页面,点击它,内容应用就会显示出来。
在这个内容应用程序中,我使用了一个垫选择控件,它不会在外部单击时关闭面板 -> 问题! 外壳应用程序似乎捕获了外部单击事件。 如果我在 shell 应用程序中使用 mat-select,一切正常。
这是我的 shell webpack 配置:
const webpack = require("webpack");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
module.exports = {
output: {
publicPath: "http://localhost:4200/",
uniqueName: "home",
},
optimization: {
runtimeChunk: false,
},
plugins: [
new ModuleFederationPlugin({
shared: {
"@angular/core": { eager: true, singleton: true },
"@angular/common": { eager: true, singleton: true },
"@angular/router": { eager: true, singleton: true }
},
}),
],
};
内容 webpack 配置:
const webpack = require("webpack");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
module.exports = {
output: {
publicPath: "http://localhost:4201/",
uniqueName: "contentModul"
},
optimization: {
runtimeChunk: false,
},
plugins: [
new ModuleFederationPlugin({
name: "content",
library: { type: "var", name: "content" },
filename: "remoteEntry.js",
exposes: {
ContentModule:
"./projects/content/src/app/content/content.module.ts",
},
shared: {
"@angular/core": { eager: true, singleton: true },
"@angular/common": { eager: true, singleton: true },
"@angular/router": { eager: true, singleton: true }
},
}),
],
};
这里是我的路由:
import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { HomeComponent } from "./home/home.component";
import { PageNotFoundComponent } from "./static-pages/page-not-found/page-not-found.component";
import { loadRemoteModule } from "./utils/federation-utils";
const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
{
path: "content",
loadChildren: () =>
loadRemoteModule({
remoteName: "content",
remoteEntry: "http://localhost:4201/remoteEntry.js",
exposedModule: "ContentModule",
}).then((m) => m.ContentModule)
},
{ path: "**", component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
您知道遗漏/错误的地方吗?
谢谢!
【问题讨论】:
标签: angular webpack angular-material webpack-module-federation