如何让 Angular2 项目在兄弟目录中找到 javascript 个文件

How to have Angular2 project find javascript files in sibling directory

我有一个目录,其中有两个单独的文件夹层次结构。一个名为 "frontend" 的目录中有一个典型的 Angular2 项目。 "frontend" 的兄弟 "common" 包含普通的旧 TypeScript 业务逻辑和该业务逻辑的 Jasmine 测试。 "common" 文件夹中的代码有自己的 package.json 和 node_modules,可以独立于 Angular2 项目构建和测试。

但是,我希望 Angular 项目在其构建中包含 "common" 代码。这取决于公共代码,反之则不然。

Angular 项目不知道其源代码树和 node_modules 之外的代码。

有人知道如何让 Angular 项目获取 "common" 目录中的依赖项吗?

您可以通过本地路径引用在 package.json 中引用 "common" 库。 https://docs.npmjs.com/files/package.json#local-paths

{
  "name": "common",
  "dependencies": {
    "bar": "file:../common"
  }
}

一旦被引用,您就可以像对待任何其他节点模块一样对待它。