10

I'm converting an existing project from js to typescript. I want to be able to set noEmit = true on one folder but have the other folder have noEmit = false.

The reason is that I have my client(angular) code set up through webpack and do not need typescript to generate the javascript for me. While the server (Node/express) still needs to be generated into javascript.

I've tried a few different combinations but haven't seem to find the right way to do it.

My only solution that I've been able to get to work is having two tsconfig.json and running a command like tsc -p src\server\tsconfig && tsc -p src\client\tsconfig

I realize that this is not a good solution, but I have not gotten a single tsconfig to work nor having a base tsconfig.

Here is the folder structure..

|-Src
|--/client
|--/server

Is there a way to achieve this using a single tsc command? Or is there a better way I should be formatting the project? Thanks!!

Flyii
  • 1,105
  • 1
  • 12
  • 21
gmoney
  • 335
  • 1
  • 5
  • 16

2 Answers2

4

I don't think there's another solution besides having multiple tsconfig.json files like you're already doing, as per this answer and this comment.

You can make this a little more streamlined by having a tsconfig.json for compilation and a separate tsconfig-build.json that you use in your package.json for building, i.e.:

// package.json
{
    "scripts": {
        "build": "tsc -p tsconfig-build.json"
    },
    // ...
}

With this setup (assuming the default tsconfig.json is in your root), running tsc from the command line will use the default tsconfig.json, but running npm run build will use tsconfig-build.json. You can also have one tsconfig extend from another, so if you have a lot of options in common, you could add a tsconfig-base.json that both configs extend from.

Galen Long
  • 3,693
  • 1
  • 25
  • 37
1

You can probably achieve what you want with the exclude property in your tsconfig.json file.

Check the documentation for the exclude property

tandrieu
  • 129
  • 1
  • 4
  • 5
    That will then exclude the client folder from the typescript compiler checking. I still want that functionality , just not have it emit – gmoney Dec 19 '18 at 17:32
  • I see i think you are stuck with your solution since you can't specify the noEmit property per files/directories. I suppose you are using ts-loader, if so then you should have the compiler checking via webpack and remove your second command – tandrieu Dec 19 '18 at 17:39