首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角垫选择与webpack模块联邦事件问题

角垫选择与webpack模块联邦事件问题
EN

Stack Overflow用户
提问于 2021-05-20 05:06:14
回答 1查看 238关注 0票数 2

我在MonoRepo中有两个Angular应用程序,一个外壳应用程序和一个内容应用程序。shell应用程序就像一个显示卡片的登录页面,点击它,内容应用程序就会显示出来。

在此内容应用程序中,我使用了mat-select控件,它不会关闭面板上的外部单击->问题!看起来外部的点击事件是由shell应用程序捕获的。如果我在shell应用程序中使用mat-select,一切都会正常工作。

这是我的shell webpack配置:

代码语言:javascript
复制
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配置:

代码语言:javascript
复制
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 }
      },
    }),
  ],
};

下面是我的路线:

代码语言:javascript
复制
    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 {}

你知道遗漏了/错了什么吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-16 07:41:14

我也有同样的问题。我遇到的问题与Angular模块的导入有关。我在我的微型前端导入了Angular的BrowserModule,这是错误的。此模块只能导入到shell应用程序的根模块中。

微前端应该只导入CommonModule。如果改为导入BrowserModule,这将破坏Angular运行时,并导致错误,如未正确捕获事件。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67610895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档