Home > Enterprise >  How to use watch flag in TypeScript with multiple projects?
How to use watch flag in TypeScript with multiple projects?

Time:11-22

I have following package.json scripts section:

"watch": "?",
"build": "npm run build:compactor && npm run build:generator && npm run build:cleaner",
"build:lambda": "npm run build:compactor:lambda && npm run build:generator:lambda && npm run build:cleaner:lambda",
"build:compactor": "tsc -p src/compactor",
"build:generator": "tsc -p src/generator",
"build:cleaner": "tsc -p src/cleaner",
"build:compactor:lambda": "npm run build:compactor && cp package.json ./dist-compactor/package.json && cd ./dist-compactor && npm install --production && zip -r ../dist-compactor.zip *",
"build:generator:lambda": "npm run build:generator && cp package.json ./dist-generator/package.json && cd ./dist-generator && npm install --production && zip -r ../dist-compactor.zip *",
"build:cleaner:lambda": "npm run build:cleaner && cp package.json ./dist-cleaner/package.json && cd ./dist-cleaner && npm install --production && zip -r ../dist-compactor.zip *",

My project consists of 3 subproject. It has main tsconfig.json file and then 3 configs which extend first one.

Standard tsc -w will ignore existing nested configuration.

One option would be to concurrently run tsc -p src/<project> -w 3 times but maybe tsc has something built in already?

CodePudding user response:

If you're using UNIX-based system, a workaround might be to use

tsc -w -p project1 & tsc -w -p project2

To run them concurrently. It will work in terms of compiling the typescript code but you might encounter strange artifacts in the console window unfortunately

CodePudding user response:

You need to run the following command

tsc -w -p project1 & tsc -w -p project2

Hope it is helpful

  • Related