tsconfig.json中的Typescript outDir设置不起作用 [英] typescript outDir setting in tsconfig.json not working
问题描述
在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构建脚本:
"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中的Typescript outDir设置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!