如何在 tsconfig.json 中指定多个源文件夹? [英] How can I specify multiple source folders in my tsconfig.json?
问题描述
我目前的项目结构如下:
I currently have the following project structure:
project/
tsconfig.json
webpack.config.js
package.json
node_modules/
...lots of dependencies
typings/
...lots of .d.ts files for the dependencies
src/
...folders for files for my projects
我的 tsonfig.json
看起来像:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"outDir": "./js",
"rootDir": "./src",
"sourceMap": true,
"jsx": "react"
},
"exclude": [
"typings/main.d.ts",
"typings/main",
"node_modules"
]
}
这一切都运行良好,我可以愉快地开发我的应用程序并在浏览器中运行它.
This all works very well and I can happily develop my application and run it in a browser.
我现在想在我的项目中添加一些单元测试,并且来自 Java 背景,我最初的直觉是将测试放在一个单独的文件夹中:
I would now like to add some unit tests to my project and coming from a Java background my initial instinct is to place the tests in a separate folder:
project/
test/
...all of my test cases
当然,test/
文件夹中的文件需要引用我src/
文件夹中的代码.我该如何设置?
Of course, the files in the test/
folder need to reference the code in my src/
folder. How do I set that up?
或者将测试内联放置在 src/
文件夹中并为它们提供单独的 webpack.config.js
文件是否更好"?
Or is it "better" to place the tests inline in the src/
folder and have a separate webpack.config.js
file for them?
对于这在大型 TypeScript 项目中的实际运作方式真的很困惑.
Really confused about how this works in practice in larger TypeScript projects.
注意:我已经看到了这个 但发现答案并不具启发性.似乎有关 filesGlob
的参考功能讨论对我有帮助,但我只是想知道人们今天是怎么做的?
Note: I have seen this but found the answer less than illuminating. It seems that the referenced feature discussion about filesGlob
would help me, but I just wonder how people are doing this today?
推荐答案
现在除了 rootDir
,你可以使用 rootDirs
Now other than rootDir
, you can use rootDirs
"rootDirs": ["./scripts", "./src"],
用于多个文件夹.
这篇关于如何在 tsconfig.json 中指定多个源文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!