Reputation:
Picture this: I've got main.ts
and sw.ts
.
How can I compile main.ts
to js/
folder and sw.ts
to root
directory? Can you give me an example?
Upvotes: 4
Views: 2788
Reputation:
I've found the solution with the help of this page: Projects References.
What worked for me was creating a new tsconfig.json
file for each directory. After that, you should use this, in the main tsconfig.json
:
"references": [
{ "path": "PATH/TO/EACH/OTHER/TSCONFIG.JSON/FILES" }
]
On top of that, you also must add this option to the compilerOptions
of each secondaries tsconfig.json
files:
"composite": true
Also, use "include"
to point to each .ts
files that that particular tsconfig.json
will use:
"include": [
"./homeWork.ts",
"./myGame.ts"
]
or
"include": [
"./*.ts" //Points to every .ts file inside that directory.
]
Now, you should be able compile it all, at once, using any of these commands from the same directory as the main tsconfig.json
:
tsc --build
;tsc -b //Alias for the above command
;tsc -w -b //Above command, including the option -w for watching changes recursively
.tsconfig.json
may have;Upvotes: 9
Reputation: 51809
It's impossible within a single compilation.
You will have to run tsc
twice with different tsconfig.json
files or -outDir
options.
Upvotes: 0