Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am trying to build an NPM command which will transpile two Typescript projects that are contained in sub directories in my application and the start my server.

I have a public folder called 'src' which contains two folders, Server and Client. There are tsconfig.json files in both as they use different module systems.

I am trying to write a command in npm which will transpile both of these Typescript roots before starting the server ut can't figure out how to so it. I wuold have thought it was something similar to this if it was possible?

tsc /src/Server/*.ts && tsc /src/Client/*.ts && node /src/Server/server

Here are my two tsconfig.json files:

in /src/Server

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true
  },
  "exclude": [
    "node_modules"
  ]
}

and in /src/Client

{
  "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

Is what I am trying to achieve possible here?

Thanks!

share|improve this question
up vote 2 down vote accepted

Yes! You can absolutely do that. I created an example repo here to demonstrate.

https://github.com/NickolasAcosta/typescript-multiproject

To make it work:

npm install
npm start

It uses the concurrently package from npm to run multiple tasks.

Given this project structure:

root
- src
  - project1
    - foo.ts
    - tsconfig.json

  - project2
    - bar.ts
    - tsconfig.json

In package.json:

{
  "name": "typescript-multiproject",
  "description": "compile multiple typescript sites with one npm script",
  "private": true,
  "scripts": {
    "start": "concurrently \"npm run tsc1\" \"npm run tsc2\"",
    "tsc2": "tsc -p src/project1",
    "tsc1": "tsc -p src/project2"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^1.8.10",
    "concurrently": "2.1.0"
  }
}
share|improve this answer
1  
Perfect. Thanks! – devoncrazylegs Jun 30 at 8:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.