为 Node tsc 编译器指定 systemJS 配置文件

Specify systemJS configuration file for Node tsc compiler

现在,Node tsc 编译器查看 tsconfig.json 文件,它看起来像这样:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  }
}

使用 "module": "system" 行,您可以指定它使用 SystemJS 来管理模块。是否可以配置 SystemJS 将使用哪个配置文件?我希望能够指定自定义模块,这样 Typescript 就不会抱怨它们,而不必为每个模块创建一个单独的 .d.ts 文件。它现在似乎没有在查看 systemjs.config.jssystem-config.js

我关于在 tsconfig.json 文件中使用 SystemJS 配置的评论仍然适用,因为没有这样做的选项。

但是,既然我明白了你想要什么,那么如果你以正确的方式构建你的代码,那么只用打字稿就可以做到。
让我们假设以下模块:

  • 模块A
    • 子模块一
    • SubModuleTwo

在 dev 中你想从 ./ModuleA/SubModuleOne 导入,但在 prod 中它应该从 ./ModuleA 导入,因为你将所有内部模块编译到一个同名文件中。

那么总是从 ./ModuleA 导入怎么样?
根据 How TypeScript resolves modules:

an import statement like import { b } from "./moduleB" in /root/src/moduleA.ts would result in attempting the following locations for locating "./moduleB":

  1. /root/src/moduleB.ts
  2. /root/src/moduleB.tsx
  3. /root/src/moduleB.d.ts
  4. /root/src/moduleB/package.json (if it specifies a "typings" property)
  5. /root/src/moduleB/index.ts
  6. /root/src/moduleB/index.tsx
  7. /root/src/moduleB/index.d.ts

因此,如果您有 ./ModuleA/index.d.ts(或 .ts,那么您可以包含所有内部模块,然后只需从 ./ModuleA 导入即可在开发和生产环境中工作。
它有点像带有 __init__.py

的 python 模块

希望对你有用。