tsconfig.json 中的打字稿 outDir 设置不起作用 [英] typescript outDir setting in tsconfig.json not working

查看:63
本文介绍了tsconfig.json 中的打字稿 outDir 设置不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package.json 中使用时,我似乎无法使 outDir 标志起作用.目录结构非常简单:tsconfig.json 位于根级别,还有一个 src/ 目录和一个 index.ts 文件以及代表其他模块的其他目录.

I can't seem to get the outDir flag working when used in package.json. Directory structure is pretty simple: tsconfig.json at the root level, together with a src/ directory and a single index.ts file plus other directories representing other modules.

在索引文件上运行 tsc 命令时,它会在它旁边而不是在构建目录中创建一个新的.我做错了什么?

When running the tsc command on the index file, it creates a new one beside it instead of in the build directory. What am I doing wrong?

我的 tsconfig:

My tsconfig:

{
  "compilerOptions": {
    "outDir": "build"
  }
}

我的 npm 构建脚本:

My npm build script:

"build": "tsc src/index.ts"

我从项目的根目录调用脚本.有趣的是,使用 --outDir 标志运行相同的脚本效果很好.

I'm calling the script from the root dir of the project. Interestingly, running the same script with an --outDir flag works just fine.

推荐答案

当你使用 tsc src/index.ts 传入文件进行编译时,你的 tsconfig.json被忽略.

When you pass in files for compilation with tsc src/index.ts, your tsconfig.json is ignored.

来自文档:

在命令行指定输入文件时,tsconfig.json文件被忽略.

When input files are specified on the command line, tsconfig.json files are ignored.

你的 npm 构建脚本应该只是 tsc 而不传递任何文件.

Your npm build script should just be tsc without passing any files.

这篇关于tsconfig.json 中的打字稿 outDir 设置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆