typescript tsconfig - 如何为多个目录(Atom)设置正确的编译器输出位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29908200/
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
tsconfig - How to set correct compiler output location for multiple directories (Atom)
提问by pixelmike
Suppose I have this directory structure:
假设我有这个目录结构:
public/
js/
lib/
test/
ts/
lib/
ts/
How would I configure it to compile lib/ts/*.ts
to public/js/lib/*.js
and test/ts/*.ts
to public/js/*.js
?
我将如何配置它来编译lib/ts/*.ts
,以public/js/lib/*.js
和test/ts/*.ts
到public/js/*.js
?
I've tried setting up a separate tsconfig.json in each ts directory with the desired outDir
, but as soon as I add a ///<reference
to a file, the compiler outputs an unwanted directory tree (on save and on build.)
我试着与期望每个TS目录设置单独的tsconfig.json outDir
,但只要我添加///<reference
到文件中,编译器输出的不必要的目录树(在保存和编译。)
回答by pixelmike
I ended up getting what I wanted with this layout:
我最终通过这种布局得到了我想要的东西:
public/
js/
lib/
test/
src/
ts/
lib/
test/
In src/ts/test/tsconfig.json:
在 src/ts/test/tsconfig.json 中:
"outDir": "../../../public/js"
In src/ts/lib/tsconfig.json:
在 src/ts/lib/tsconfig.json 中:
"outDir": "../../../public/js/lib"
In src/ts/test/test.ts:
在 src/ts/test/test.ts 中:
/// <reference path="../lib/CoolStuff.ts" />
In Atom, if you're working in src/ts/lib, building will compile those files into public/js/lib.
在 Atom 中,如果您在 src/ts/lib 中工作,则构建会将这些文件编译到 public/js/lib 中。
If you're working in src/ts/test, the build will compile *.ts in test - as well as all files referenced. I don't see a way to prevent referenced file compilation, but at least with this layout they go to the same location.
如果您在 src/ts/test 中工作,则构建将在 test 中编译 *.ts -以及所有引用的文件。我没有看到阻止引用文件编译的方法,但至少在这种布局下,它们会到达相同的位置。
回答by basarat
How would I configure it to compile lib/ts/.ts to public/js/lib/.js and test/ts/.ts to public/js/.js?
我将如何配置它以将 lib/ts/ .ts编译为 public/js/lib/.js 并将 test/ts/ .ts编译为 public/js/.js?
If you want to compile test
and public
in a singlecompilation context then effectively your ts tree is :
如果您想在单个编译上下文中进行编译test
,那么实际上您的 ts 树是:public
test/
ts/
lib/
ts/
Therefore if you use an outDir
of ./public/js
you will get:
因此,如果您使用其中的一个outDir
,./public/js
您将获得:
public/
js/
test/
ts/
lib/
ts/
This is because the relativenature of lib/ts
to test/ts
needs to be preserved by outDir
. This is a limation in how you are trying to organize your project.
这是因为to的相对性质需要由 保留。这是您尝试组织项目的方式的限制。lib/ts
test/ts
outDir
Reorganize your project as
将您的项目重新组织为
ts/
test/
lib/