snippetjavascriptCriticalCanonical
How can I get the Typescript compiler to output the compiled js to a different directory?
Viewed 0 times
typescriptdirectoryhowoutputthecompiledcompilercandifferentget
Problem
I'm fairly new to TypeScript, and right now I have .ts files in several places throughought my project structure:
Right now, when my files are compiled, they are compiled to the same directory that the .ts fles are in:
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:
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.
app/
|-scripts/
|-app.ts
|
|-classes/
| |-classA.ts
| |-classB.ts
|
|-controllers/
| |-controllerA.ts
| |-controllerB.ts
|
|-otherStuff/
|-otherstuffA.tsRight 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.jsWhile 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.jsIs 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.
Solution
Since Typescript 1.5, this can also be set in the
original answer
Use the option
From the command line documentation
tsconfig.json file:"compilerOptions": {
"outDir": "DIRECTORY"
...original answer
Use the option
--outDir on tsc (configured within the File Watcher in IntelliJ)From the command line documentation
--outDir DIRECTORY Redirect output structure to the directory.Code Snippets
"compilerOptions": {
"outDir": "DIRECTORY"
...Context
Stack Overflow Q#24454371, score: 263
Revisions (0)
No revisions yet.