How to run typescript compiler as a package.json script without grunt or gulp

SuperUberDuper picture SuperUberDuper · Jul 31, 2015 · Viewed 42.3k times · Source

I don't want to use grunt or gulp to compile ts files. I just want to do it in my package.json something like this:

  "scripts": {
    "build": "tsc main.ts dist/"
  },

is it possible?

Answer

basarat picture basarat · Aug 1, 2015

"build": "tsc main.ts dist/"

Highly recommend you use tsconfig.json and then the -p compiler option to build your code. Look at: Compilation-Context

Setup

Here is the setup for using tsc with NPM scripts

init

npm init
npm install typescript --save

And then in your package.json add some scripts:

"scripts": {
    "build": "tsc -p ./src",
    "start": "npm run build -- -w"
},

Use

  • For build only: npm run build
  • For building + live watching : npm start

Enjoy 🌹