使用spec / test文件夹设置tsconfig

联合的:

说我把我的代码放在下面src并在下面测试spec

+ spec
+ --- classA.spec.ts
+ src
+ --- classA.ts
+ --- classB.ts
+ --- index.ts
+ tsconfig.json

我只想转移src到该dist文件夹。既然index.ts是我包装的入口,我的tsconfig.json样子是这样的:

{
  "compileOptions": {
    "module": "commonjs"
    "outDir": "dist"
  },
  "files": {
    "src/index.ts",
    "typings/main.d.ts"
  }
}

但是,这tsconfig.json不包括测试文件,因此我无法解析其中的依赖项。

另一方面,如果我将测试文件包括在内,tsconfig.json它们也将被转换为dist文件夹。

我该如何解决这个问题?

联合的:

我最终定义了多个配置文件,并使用extends它们来简化它们。

说我有两个文件:tsconfig.jsontsconfig.build.json

// tsconfig.json
{
  ...
  "exclude": [...]
}

// tsconfig.build.json
{
  ...
  "files": [ "typings/index.d.ts", "src/index.ts" ]
}

这样,我可以很好地控制构建(使用tsc -p tsconfig.build.json)和ts language service(IDE)处理的内容。

更新:现在随着项目的增长,我最终拥有更多的配置文件。我使用TypeScript现在提供的“扩展”功能:

// tsconfig.base.json
{
  // your common settings. Mostly "compilerOptions".
  // Do not include "files" and "include" here,
  // let individual config handles that.
  // You can use "exclude" here, but with "include",
  // It's pretty much not necessary.
}

// tsconfig.json
{
  // This is used by `ts language service` and testing.
  // Includes source and test files.
  "extends": "./tsconfig.base.json",
  "atom": { ... },
  "compilerOptions": {
    // I set outDir to place all test build in one place,
    // and avoid accidentally running `tsc` littering test build to my `src` folder.
    "outDir": "out/spec"  
  }
  "include": [ ... ]
}

// tsconfig.commonjs.json or tsconfig.systemjs.json or tsconfig.global.json etc
{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    // for some build this does not apply
    "declaration": true/false,
    "outDir": "dist/<cjs, sys, global, etc>",
    "sourceRoot": "..."
  },
  // Only point to typings and the start of your source, e.g. `src/index.ts`
  "files": [ ... ],
  "include": [ ... ]
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何触摸与当前时间的文件夹使用设置上次修改的日期和时间?

在子文件夹中使用pytest where test

如何递归设置权限,文件夹为700,文件为600,而不使用find

使用Ansible设置程序重新引导Vagrant计算机时,同步文件夹丢失

如何使用Gradle在Eclipse中将文件夹设置为源文件夹?

使用PowerShell设置特殊文件夹的位置

如何使用YAML文件在Elastic Beanstalk中设置文件夹权限?

使用WiX Toolset设置ProgramData中现有文件夹和文件的权限

使用Powershell递归设置文件夹权限?

如何使用三个最近的文件夹设置提示../c/Users/test

在不同区域中使用PowerShell设置文件夹权限

使用文件夹通配符

如何使用一个命令在rspec中运行多个spec文件夹?

如何使用应用程序专用文件夹中的文件设置通知声音?

使用Haskell的文件夹

使用Nest设置两个不同的静态文件夹

如何使用子文件夹中的ico文件设置WPF应用程序图标

Shiny不会将下载的文件保存在使用output_dir设置的文件夹中

使用有效的HOME文件夹设置在NodeJS中生成child_process

了解使用默认&html文件夹的Vagrant Synced文件夹设置

使用chown设置文件夹的所有子文件夹和文件的所有权?

使用If语句文件夹和子文件夹

如何使用 setfacl 为文件和文件夹设置不同的默认权限?

使用 cmd 行将文件夹和文件设置为只读

使用 Express 如何为动态内容设置静态文件夹和视图文件夹

如何为使用`dask.dataframe.to_parquet()`创建的文件夹设置文件夹权限(mkdir模式)?

设置 Docker 以使用文件系统文件夹来存储数据库,UBUNTU?

如何使用 tsconfig 将 .env 文件移动到构建文件夹中

使用 Python 设置文件夹时间戳