小编Mik*_*ike的帖子

模块联合共享服务

我正在使用 Angular 11 和 Webpack 5 开展一个新项目。我的工作基于 Manfred Steyer 的Module Federation Plugin Example repo,它使用 Angular CLI。我不知道如何从我的两个应用程序之间共享的本地 Angular 库共享单例服务

我会尽力解释我的设置.. 真的很抱歉这会持续多久。

简化的文件结构

root
  package.json
  projects/
    shell/
      src/app/
        app.module.ts
        app.component.ts
      webpack.config.ts <-- partial config
    mfe1/
      src/app/
        app.module.ts
        app.component.ts
      webpack.config.ts <-- partial config
    shared/
      src/lib/
        global.service.ts
      package.json <-- package.json for lib

Run Code Online (Sandbox Code Playgroud)

两个 app.component.ts 文件是相同的

import {GlobalService} from 'shared';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  constructor(shared: SharedService) {}
}
Run Code Online (Sandbox Code Playgroud)

global.service.ts

import { Injectable } from '@angular/core'; …
Run Code Online (Sandbox Code Playgroud)

webpack angular-cli angular nrwl-nx webpack-5

5
推荐指数
1
解决办法
4762
查看次数

标签 统计

angular ×1

angular-cli ×1

nrwl-nx ×1

webpack ×1

webpack-5 ×1