0
votes

Typescript documentation states that the tsconfig.json file should be located at the project root:

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

Due to my project requirements I have to have multiple versions of this file (Angular AOT, Universal, Webpack each requires different settings).

This clutters the project root so ideally I want to move them to somewhere else, for example under /config/...

Doing so, however, confuses ts compiler and the filepaths dont resolve properly. For example exclude settings below will still get included to the compile

  "exclude": [
    "node_modules",
    "compiled",
    "e2e/**/*.ts",
    "src/main.browser.universal.aot.ts",
    "src/app/app.module.universal.node.ts"
  ],

Putting ../ in front of them doesn't fix it. Anyone has any idea or example to demonstrate how tsconfig.json can be placed somewhere else?

1

1 Answers

0
votes

For this kind of things I would recommend to use any of the available task runners, the most popular are: grunt and gulp

There are plenty of articles out there on how to setup typescript compilation (for example).

Here is my sample of how to work with tsconfig from gulp:

gulp.task('build.js.dev', () => 
{
    var tsProject = ts.createProject('tsconfig.json', {
        typescript: require('typescript')
    });

    var tsResult = tsProject.src()
        .pipe(sourcemaps.init())   
        .pipe(tsProject());  

    return merge([
        //Write definitions 
        tsResult.dts.pipe(gulp.dest(TEMP_TARGET_FOLDER)),
        //Write compiled js
        tsResult.js.pipe(sourcemaps.write(
            ".", 
            { 
                includeContent: false, 
                sourceRoot: "../dist" 
                // mapSources: function(sourcePath) 
                // {
                //     console.log(sourcePath);
                //     return sourcePath;//.replace('../', '');
                // } 
            })).pipe(gulp.dest(TEMP_TARGET_FOLDER))]);
});