0

Say I have a tsconfig.json file in a certain directory, and it looks like so:

{
  "compilerOptions": {
    "outDir": "./target",
    "types": [
      "node"
    ],
    "typeRoots": [
      "node_modules/@types"
    ],
    "target": "es5",
    "module": "commonjs",
    "noImplicitAny": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "allowJs": false,
    "allowUnreachableCode": true,
    "lib": [
      "es2015",
      "es2016",
      "es2017"
    ]
  },
  "exclude": [
    "node_modules"
  ]
}

what this will do is transpile all .ts files below this tsconfig.json file, into a directory adjacent to the tsconfig.json file, but what if we want to transpile the files to a location relative to the source file, not relative to the tsconfig.json file.

Is there a way to do that?

In visual terms, we have this now:

test/
  tsconfig.json
  src/
    foo1/
      bar1.ts
    foo2/
      bar2.ts
  target/
    bar1.js
    bar2.js

but I am looking for this instead:

test/
  tsconfig.json
  src/
    foo1/
      bar1.ts
    target/
      bar1.js
    foo2/
      bar2.ts
    target/
      bar2.js

As far as tsconfig.json, that might look like:

 "outDir": "$(dirname ${sourceFile})/@target",
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 1
    Don't think that is possible at the moment. Why do you want to do that? how about just next to each other? In that case just remove the `outDir` – unional Jun 28 '17 at 02:13
  • Yeah..I am trying to create a generic testing system with the src files and target files in separate directories. I agree it's simple and convenient to have them in the same directory, and it's standard practice with TS. At the moment, I cannot articulate exactly why I want them in separate directories. Mostly because it allows for a generic way for my tool to distinguish between src and target files. – Alexander Mills Jun 28 '17 at 02:19
  • 1
    You can use `glob` to detect if the file is src or target if you mix ts and js in your project. basically get all ts file, and all js files, and do a filter to see if there are js file but no ts files. Those are src, while others are target,. – unional Jun 28 '17 at 02:37

0 Answers0