I have a project written in TypeScript and I use a task runner for building (whatever: Gulp, Jake, etc.). The TypeScript compiler i use is the one I installed from NPM :
npm install typescript
Important: As you can see there is no global -g
parameter and this is on purpose. As I need to use a specific version of the compiler with some modifications.
tsc
programmaticallySo I want to invoke the compiler from my Javascript file configuring my task manager:
var tsc = require("typescript");
function compile() {
tsc.compile(...); // I would like to do something like this
}
Can I do that? I have tried, but not getting much luck so far.
You sure can. There are numerous tools - tsify
, ts-node
, ts-loader
- that are built using the TypeScript Compiler API .
However, it's a little bit more complicated than a single compile
call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.