【问题标题】:How can I prevent cross-project in Angular workspace?如何防止 Angular 工作区中的跨项目?
【发布时间】:2020-11-27 21:06:27
【问题描述】:

假设我有一个具有给定结构的项目:

projects
|-app1
|-app2
|-common
node_modules
pakcage.json
tsconfig.json
angular.json
... (rest of the root files)

现在在app1 的文件中,我可以这样写: import { Repository } from '../../../app2/src/app/query/repository'; 即使它工作(正确构建),我想避免这样的导入,例如有时,其中一个项目被移动到单独的仓库中,通常是为了保持干净的项目结构。

有没有办法指示 angular/typescript 在服务/构建期间抛出错误,不允许跨项目导入?

【问题讨论】:

  • 你可能想看看 Nx nx.dev

标签: angular typescript angular-cli angular-workspace-configuration


【解决方案1】:

找到了解决方案 - 它是 tslint.json 中的 import-blacklist 属性。在我的场景中,它看起来像:

{
  "extends": "../../tslint.json",
  "rules": {
    "no-output-native": false,
    "import-blacklist": [true,
      [".*the-other-project.*"]
    ]
  }
}

【讨论】:

    猜你喜欢
    • 2022-11-10
    • 2019-10-16
    • 2020-05-14
    • 2021-05-21
    • 1970-01-01
    • 2018-06-08
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多