打字稿:使 tsconfig 发出一个文件夹而不是另一个文件夹 [英] Typescript: Make tsconfig emit one folder but not the other folder

查看:21
本文介绍了打字稿:使 tsconfig 发出一个文件夹而不是另一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有项目从 js 转换为打字稿.我希望能够在一个文件夹上设置 noEmit = true 但让另一个文件夹具有 noEmit = false.

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.

原因是我通过 webpack 设置了我的客户端(angular)代码并且不需要打字稿来为我生成 javascript.而服务器(Node/express)仍然需要生成为 javascript.

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.

我能够开始工作的唯一解决方案是使用两个 tsconfig.json 并运行类似 tsc -p src\server\tsconfig && 的命令.tsc -p src\client\tsconfig

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

我意识到这不是一个好的解决方案,但我没有得到一个单独的 tsconfig 工作,也没有一个基本的 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.

这是文件夹结构..

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

有没有办法使用单个 tsc 命令来实现这一点?或者有更好的方法来格式化项目吗?谢谢!!

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

推荐答案

根据 这个答案这条评论.

您可以通过使用 tsconfig.json 进行编译和在 package.json 中使用的单独 tsconfig-build.json 来简化此操作建筑,即:

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"
    },
    // ...
}

使用此设置(假设默认 tsconfig.json 是在您的根目录)中,从命令行运行 tsc 将使用默认的 tsconfig.json,但运行 npm run build 将使用 tsconfig-build.json.您还可以让 一个 tsconfig 从另一个扩展,所以如果你有很多共同的选项,你可以添加一个 tsconfig-base.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.

这篇关于打字稿:使 tsconfig 发出一个文件夹而不是另一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆