Search code examples
angulartypescripttsctsconfig

Angular 2 - tsconfig outDir


I'm currently developing an Angular2 application and I'm facing the following problem - I have some unit tests in my project and I don't want them to be sent to the /dist folder along side with my other code. My project structure is as follows:

dist/
 -app (compiled from src/app)
 -test (compiled from src/test)
src/
 -app
 -test

Now, using the "outDir" in my tsconfig.json I'm compiling all .js files to the /dist directory. What I want to do is simply compile all app/ ts files and send them to the /dist directory, but keep the compiled .js files from my /test directory there. It should look like this :

dist/
 -app (compiled from src/app)
src/
 -app
 -test ( all compiled js files remain here )

Any idea?

Thanks


Solution

  • You could try the following:

    - src/
      - app/
      - test/
        - tsconfig.json
      - tsconfig.json
    

    tsconfig.json for src/

    {
      "compilerOptions": {
        "outDir": "../dist"
        [...]
      },
      "exclude": [],
      "include": ["./app"]
      [...]
    }
    

    tsconfig.json for test/

    {
      "compilerOptions": {
        "outDir": "./"
        [...]
      },
      "extends": "../tsconfig.json",
      "include": ["./"]
      [...]
    }
    

    Be careful to compile your code you will have to run tsc twice.

    • From the src folder, to compile your application code.

    • From the test folder, to compile your tests.