TypeScript - 如何将编译的文件保存在单独的目录中? [英] TypeScript - How to keep compiled files in a separate directory?
问题描述
我是TypeScript的新手,现在我在几个地方都有.ts文件来完成我的项目结构:
I'm fairly new to TypeScript, and right now I have .ts files in several places throughought my project structure:
app/
|-scripts/
|-app.ts
|
|-classes/
| |-classA.ts
| |-classB.ts
|
|-controllers/
| |-controllerA.ts
| |-controllerB.ts
|
|-otherStuff/
|-otherstuffA.ts
现在,当我的文件被编译,它们被编译到.ts文件所在的目录:
Right now, when my files are compiled, they are compiled to the same directory that the .ts fles are in:
app/
|-scripts/
|-app.ts
|-app.js
|
|-classes/
| |-classA.ts
| |-classB.ts
| |-classA.js
| |-classB.js
|
|-controllers/
| |-controllerA.ts
| |-controllerB.ts
| |-controllerA.js
| |-controllerB.js
|
|-otherStuff/
|-otherstuffA.ts
|-otherStuffA.js
虽然我喜欢.js文件与.ts文件保持相同目录结构的方式,但我不想跟踪我的VCS中的.js文件,所以我想保留所有我的JavaScript文件在一个单独的目录树中(我可以添加到.gitignore),如下所示:
While I like the way that the .js files keep the same directory structure as the .ts files, I don't want to track the .js files in my VCS, so I'd like to keep all of my JavaScript files in a separate directory tree (that I can then add to .gitignore), like so:
app/
|-scripts/
| |-app.ts
| |
| |-classes/
| | |-classA.ts
| | |-classB.ts
| |
| |-controllers/
| | |-controllerA.ts
| | |-controllerB.ts
| |
| |-otherStuff/
| |-otherstuffA.ts
|
|-js/
|-app.js
|
|-classes/
| |-classA.js
| |-classB.js
|
|-controllers/
| |-controllerA.js
| |-controllerB.js
|
|-otherStuff/
|-otherstuffA.js
是否有设置或选项会告诉TypeScript编译器执行此操作?此外,我不确定它是否相关,但我使用的是WebStorm。
Is there a setting or option somewhere that will tell the TypeScript compiler to do this? Also, I'm not sure if it's relevant, but I am using WebStorm.
推荐答案
使用选项 - outDir
(在IntelliJ中的文件观察器中配置)
Use the option --outDir
on tsc (configured within the File Watcher in IntelliJ)
从命令行文档中
- outDir DIRECTORY将输出结构重定向到目录。
编辑
自Typescript 1.5以来,这也可以在 tsconfig.json
文件中设置:
Since Typescript 1.5, this can also be set in the tsconfig.json
file:
"compilerOptions": {
"outDir": "DIRECTORY"
...
这篇关于TypeScript - 如何将编译的文件保存在单独的目录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!