如何让TypeScript编译器不发出目录结构
在我当前的TypeScript项目中,我有以下文件结构:
project ├─app │ └─index.html ├─test └─src ├─app │ ├─tsconfig.json │ └─app.ts ├─lib │ └─lib.ts └─test ├─tsconfig.json └─test.ts
我想实现的是,当编译这个项目的app
并test
生成的文件结构如下所示:
project ├─app │ ├─index.html │ └─app.js ├─test │ ├─lib │ │ └─lib.js │ └─test.js └─src └─...
或这个:
project ├─app │ ├─index.html │ └─app.js ├─test │ ├─lib.js │ └─test.js └─src └─...
我有一个库位于lib目录中。 它被app.ts使用,然后在网页上使用。 testing位于testing目录内。 我实际得到的是:
project ├─app │ ├─index.html │ └─app.js ├─test │ ├─lib │ │ └─lib.js │ └─test │ └─test.js └─src └─...
注意额外的test
。
src/test/tsconfig.json
文件如下所示:
{ "compileOnSave": true, "compilerOptions": { "target": "es2016", "lib": [ "dom", "es2016" ], "outDir": "../../test", "noImplicitAny": true, "noImplicitThis": true, "noImplicitReturns": true, "module": "commonjs" }, "files": [ "test.ts" ] }
因为我想使用node.js在我的机器上执行这些testing,所以我不得不selectcommonjs
作为模块系统。 这不会像amd
-module系统那样合并所有的TypeScript模块。 所以据我所知tsc
search所有涉及的模块的第一个共同的父目录,并使该输出的基本目录。 这个通用目录是src
,这就是为什么在输出目录中有多余的目录。
所以我的问题是: 如何告诉TypeScript编译器使用src/test
作为输出的根目录,以便将test.js
放入test/test.js
而不是test/test/test.js
?
设置"rootDir": "./"
不起作用,因为编译器会输出一个错误:
error TS6059: File '[...]/lib/lib.ts' is not under 'rootDir' '[...]/src/test/'. 'rootDir' is expected to contain all source files.