编译部分 Typescript 项目导致错误

问题描述 投票:0回答:1

我有一个 Typescript 项目,其中包含两个主要文件夹:

src
test
。 编译TS代码时,我只想编译
src
文件夹。我不需要
dist
文件夹中的测试。

所以,我在

tsconfig.json
中设置这些设置:

"rootDir": "./src",
"outDir": "./dist",

我认为这就是做到这一点的方法。但不幸的是,当我运行

tsc
编译器时,我收到一条错误消息:

error TS6059: File '...my-proj/test/test.ts' is not under 'rootDir' '...my-proj/src'. 'rootDir' is expected to contain all source files.
  The file is in the program because:
    Matched by default include pattern '**/*'

(另一个意想不到的结果是,除了将

src/*
文件编译到
dist
文件夹之外,编译器还会在
js
文件夹中创建
test
文件,与原始文件并排。)

我怎样才能实现我的目标?

typescript tsc
1个回答
0
投票

这是因为您没有从打字稿编译中排除测试文件夹,或者您没有设置要包含的目录或文件。

包含您想要编译的文件或排除您不需要的文件

这是实现它的示例

tsconfig.json

{
   "include": ["src/**/*"],
   "exclude": ["node_modules", "test/**/*"],
}

© www.soinside.com 2019 - 2024. All rights reserved.