Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: Make tsconfig emit one folder but not the other folder

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!!

like image 489
gmoney Avatar asked Dec 19 '18 17:12

gmoney


2 Answers

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.

like image 157
Galen Long Avatar answered Oct 13 '22 17:10

Galen Long


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

Check the documentation for the exclude property

like image 36
tandrieu Avatar answered Oct 13 '22 18:10

tandrieu