我在项目的根目录中有一个松散的实用程序脚本name.ts
。当需要时,我使用ts-node
调用它。此脚本在实际源代码中的任何位置都未被引用。
我的程序的实际源代码在src
下。
每当我尝试运行tsc
(在tsconfig.json
中,rootDir
被设置为./src
)时,它抛出:
error TS6059: File '/home/rijndael/projects/mc/js/lua/generate.ts' is not under 'rootDir' '/home/rijndael/projects/mc/js/lua/scripts-ts'. 'rootDir' is expected to contain all source files.
为什么会这样呢?
发布于 2020-11-23 23:00:23
正如您在TypeScript docs中看到的,在使用outDir
时,rootDir
仅用于目录结构。您需要做的是分别使用include
或exclude
配置选项告诉TypeScript要包括(或排除)哪些文件。
在你的例子中,你可以添加include: ['src/**/*']
来只使用你的源目录中的文件,或者用exclude: ['utilities/**/*']
来排除你的脚本(用你的脚本文件夹替换‘include: ['src/**/*']
’)。
示例tsconfig可能如下所示:
{
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
// your compile options
},
"include": ["src/**/*"], // only include your src directory
"exclude": ["**/*.spec.ts"] // exclude tests and add scripts if you have any in "src/"
}
include
的工作方式类似于白名单。只有与这里的任何glob模式匹配的文件才会包含在您的构建中。exclude
的工作方式类似于黑名单。与这里的任何glob模式匹配的文件将从您的构建中排除(即使由include
匹配)。
https://stackoverflow.com/questions/64970699
复制相似问题