tscpp
tscpp

Reputation: 1566

TSconfig: compile a new js folder for each ts folder

I want to compile a new js folder for each script folder. Is that possible with tsconfig.json?

Directories

folder1
  scripts
    index.ts

folder2
  scripts
   index.ts
tsconfig.json

Directories after compile

folder1
  scripts
    index.ts
  js
    index.js

folder2
  scripts
    index.ts
  js
    index.js
tsconfig.json

Upvotes: 0

Views: 180

Answers (1)

Fenton
Fenton

Reputation: 250922

Disclaimer... this doesn't answer your question specifically, because what you want to do breaks with convention. Even if you manage to do it your way, I think you'll find the pain will outweigh the benefit.

The simplest way is to specify an outDir output directory. Your existing folder structure will be maintained in the output directory, with all the JavaScript and TypeScript kept cleanly separated.

{
    "compilerOptions": {
        "outDir": "./scripts",
        ...
    }
}

So if you start with:

/component-a
    index.ts
/component-b
    index.ts

You'll end up with the folders mirrored in the output directory.

/component-a
    index.ts
/component-b
    index.ts
/scripts
    /component-a
        index.js
    /component-b
        index.js

Unless you plan to deploy both (?) you don't normally want the TypeScript and JavaScript intermingled.

Upvotes: 1

Related Questions