Search code examples
visual-studio-2013typescriptweb-essentials

Compiling typescript files into one file, but some of them as single files


I have a project with lots of Typescript files, which I want to compile into one file. I can set that up in Visual Studio, no problem.

But then I also have some files that should be compiled in their own file.

Basically, I have a structure like this:

js/
tests/

Everything in js/ should be compiled into one file, everything in tests/ should be each an individual file. I could now compile into individual files, and use a bundle with Webessentials, but this is not so good to debug.

Is there a way to tell the Typescript compiler to have different compile settings for different folders? I'd also really like to still have it compile on saving a file.


Solution

  • Update on this: @curpa answer back then was the correct one, but since then, some updates have been added to Typescript.

    Since, I think Typescript 1.8 (not quite sure?), you can use tsconfig files to configure typescript configuration. You can add those files into different folders, and the typescript compiler will then transpile the files according to the tsconfig in the same folder, or one of its parent folders.

    With this, you can then configure your project to transpile with different settings in different folders.

    In my example, with folders js/ and tests/, this might look like this: tsconfig.json in js/

    {
        "compilerOptions": {
            ...
            "outFile": "../../built/local/tsc.js"
        },
        "include": [
            "**/*"
        ]
    }
    

    tsconfig.json in tests/

    {
        "compilerOptions": {
            ...
            // not outfile specified, ts files will be transpiled in
            // a js file, for each
        },
        "include": [
            "**/*"
        ]
    }