Angular模块联邦--共享模块无法被急切加载使用。
创始人
2024-10-28 14:31:14
0

在使用共享模块的应用程序中,需要将共享模块设置为懒加载模式。假设我们有一个实现共享模块的Angular项目,称为“shared”,并有一个使用该共享模块的主应用程序,称为“main”。我们需要进行以下更改:

  1. 在“shared”项目的app.module.ts文件中,将模块的加载方式设置为懒加载模式:
@NgModule({
  imports: [],
  exports: [],
  declarations: [],
  providers: [],
  bootstrap: [],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  // 加载方式设置为懒加载模式
  // (当使用 webpack5 时配置文件webpack.config.js中,需要设置module.federation.shared.type为'lazy')
  // (当使用 webpack5 时,需要设置export来使模块可被引用)
  // (当使用 webpack4 时,需要将entry中对应模块设置为输出文件,然后在主模块使用script引入)
  ...(isWebpack5 ?
    { import: [''], type: 'lazy', shareScope: 'default', export: 'sharedModule' } :
    { },
)
export class AppModule { }
  1. 在“main”项目的app.module.ts文件中,导入共享模块:
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    // 导入共享模块
    // (当使用 webpack5 时配置文件webpack.config.js中,需要设置module.federation.shared.type为'lazy')
    // (当使用 webpack5 时,需要设置import来引用模块)
    // (当使用 webpack4 时,需要将entry中对应模块设置为输出文件,然后在主模块使用script引入)
    ...(isWebpack5 ? [
        loadRemoteModule({
            remoteEntry: 'http://localhost:5000/remoteEntry.js',
            remoteName: 'shared',
            exposedModule: './sharedModule'

相关内容

热门资讯

透视玄学!aapoker透视插... 透视玄学!aapoker透视插件(透视)透视插件(确实存在有挂)一、aapoker透视插件AI软件牌...
透视工具!aapoker真的假... 透视工具!aapoker真的假的(透视)辅助插件工具(其实有挂)1、全新机制【aapoker真的假的...
透视能赢!aapoker脚本怎... 透视能赢!aapoker脚本怎么用(透视)万能辅助器(总是有挂);1、每一步都需要思考,不同水平的挑...
透视黑科技!aapoker俱乐... 透视黑科技!aapoker俱乐部靠谱吗(透视)透视方法(其实存在有挂)aapoker俱乐部靠谱吗辅助...
透视ai!aapoker能控制... 透视ai!aapoker能控制牌吗(透视)插件(总是是有挂)1、首先打开aapoker能控制牌吗最新...
透视黑科技!aapoker怎么... 透视黑科技!aapoker怎么提高中牌率(透视)插件(本来真的有挂)1、全新机制【aapoker怎么...
透视实锤!aapoker免费透... 透视实锤!aapoker免费透视脚本(透视)插件(切实有挂);运aapoker免费透视脚本辅助工具,...
透视脚本!aapoker怎么开... 透视脚本!aapoker怎么开辅助器(透视)插件(原来存在有挂)透视脚本!aapoker怎么开辅助器...
透视肯定!aapoker插件下... 透视肯定!aapoker插件下载(透视)透视方法(原来有挂)1、在aapoker插件下载ai机器人技...
透视软件!aapoker怎么设... 透视软件!aapoker怎么设置抽水(透视)透视插件(果然是真的有挂)1、进入游戏-大厅左侧-新手福...