typescript tsconfig.json 中的打字稿 outDir 设置不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45661027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
typescript outDir setting in tsconfig.json not working
提问by aryzing
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.
我似乎无法获得outDir
标志使用时的工作package.json
。目录结构非常简单:tsconfig.json
在根级别,连同一个src/
目录和一个 index.ts 文件以及代表其他模块的其他目录。
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?
在tsc
索引文件上运行命令时,它会在它旁边而不是在构建目录中创建一个新文件。我究竟做错了什么?
My tsconfig:
我的 tsconfig:
{
"compilerOptions": {
"outDir": "build"
}
}
My npm build script:
我的 npm 构建脚本:
"build": "tsc src/index.ts"
I'm calling the script from the root dir of the project. Interestingly, running the same script with an --outDir
flag works just fine.
我正在从项目的根目录调用脚本。有趣的是,使用--outDir
标志运行相同的脚本效果很好。
回答by Saravana
When you pass in files for compilation with tsc src/index.ts
, your tsconfig.json
is ignored.
当您传入文件进行编译时tsc src/index.ts
,您的将tsconfig.json
被忽略。
From the documentation:
从文档:
When input files are specified on the command line, tsconfig.json files are ignored.
在命令行上指定输入文件时,将忽略 tsconfig.json 文件。
Your npm build script should just be tsc
without passing any files.
您的 npm 构建脚本应该只是tsc
不传递任何文件。
回答by joshweir
If you are using the incremental
compiler option, you may not be getting output if you have deleted / modified files in your outDir
but have not removed the .tsbuildinfo
file.
如果您使用incremental
编译器选项,如果您删除/修改了您outDir
的.tsbuildinfo
文件但尚未删除该文件,则可能无法获得输出。
My issue was a bit different, but Google brought me here - so figured others may also.
我的问题有点不同,但谷歌把我带到了这里 - 所以想其他人也可能会。
回答by chandoo
This is my folder structure.
这是我的文件夹结构。
Keep the typescript files in src folder and keep the tsconfig.json in root.
将打字稿文件保存在 src 文件夹中,并将 tsconfig.json 保存在根目录中。
In tsconfig json file add foldername for outDir in compilerOptions
在 tsconfig json 文件中,在 compilerOptions 中为 outDir 添加文件夹名
"compilerOptions": {
"outDir": "build",
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"sourceMap": true
},
and run the below commands.
并运行以下命令。
just cd to the root folder and type
只需 cd 到根文件夹并键入
tsc
tsc
or
或者
tsc --outDir .
tsc --outDir 。
which will build the outDir folder with js and map.js files.
这将使用 js 和 map.js 文件构建 outDir 文件夹。
source: https://github.com/Microsoft/TypeScript/issues/10585
回答by Ash Blue
You need to declare your tsconfig file location instead of the file you want to build.
您需要声明您的 tsconfig 文件位置而不是您要构建的文件。
tsc --build mocks/tsconfig.json