最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Invoking TypeScript compiler as NPM module - Stack Overflow

programmeradmin4浏览0评论

I have a project written in TypeScript and I use a task runner for building (whatever: Gulp, Jake, etc.). The TypeScript piler 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 piler with some modifications.

Calling tsc programmatically

So I want to invoke the piler from my Javascript file configuring my task manager:

var tsc = require("typescript");

function pile() {
  tscpile(...); // I would like to do something like this
}

Can I do that? I have tried, but not getting much luck so far.

I have a project written in TypeScript and I use a task runner for building (whatever: Gulp, Jake, etc.). The TypeScript piler 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 piler with some modifications.

Calling tsc programmatically

So I want to invoke the piler from my Javascript file configuring my task manager:

var tsc = require("typescript");

function pile() {
  tsc.pile(...); // I would like to do something like this
}

Can I do that? I have tried, but not getting much luck so far.

Share Improve this question edited Aug 12, 2016 at 21:29 Andry asked Aug 12, 2016 at 21:17 AndryAndry 16.9k30 gold badges156 silver badges265 bronze badges 2
  • Have a look at gulp-typescript – Aleksey L. Commented Aug 14, 2016 at 5:19
  • I think this is what you are looking for – Jthorpe Commented Jan 22, 2022 at 0:53
Add a ment  | 

1 Answer 1

Reset to default 6

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 plicated than a single pile call.

发布评论

评论列表(0)

  1. 暂无评论