如何获取Typescript编译器将已编译的js输出到其他目录? [英] How can I get the Typescript compiler to output the compiled js to a different directory?

查看:279
本文介绍了如何获取Typescript编译器将已编译的js输出到其他目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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.

推荐答案

在tsc上使用选项--outDir(在IntelliJ的File Watcher中配置)

Use the option --outDir on tsc (configured within the File Watcher in IntelliJ)

从命令行文档中获取

--outDir DIRECTORY Redirect output structure to the directory.

修改

从Typescript 1.5开始,也可以在tsconfig.json文件中进行设置:

Since Typescript 1.5, this can also be set in the tsconfig.json file:

"compilerOptions": {
    "outDir": "DIRECTORY"
    ...

这篇关于如何获取Typescript编译器将已编译的js输出到其他目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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