Ste*_*ong 15 typescript tsconfig
从文档中可以看出,它include
指定了要包含在程序中(即在编译过程中)的文件名或模式数组。同样,rootDir
是包含要包含在编译过程中的应用程序源代码的文件夹的路径。
"include": ["./src/"],
"exclude": ["node_modules/*", "test/*"],
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"rootDir": "./src",
"outDir": "./dist/",
}
Run Code Online (Sandbox Code Playgroud)
那他们有什么区别呢?
Cap*_*iel 20
include
顶级选项定义将包含的文件。它相对于.tsconfig.json
并默认为**
,表示项目中的所有文件。外部文件include
不会编译。
该compilerOptions.rootDir
选项定义树的根位于outDir
。默认情况下,它使用包含的文件夹之间的公共路径。src/services/user.ts
这意味着在具有两个文件和 的项目中src/services/auth.ts
,rootDir
将默认为src/services/
(即所有输入文件的最长公共路径段)。输出目录如下所示:
dist\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 auth.js\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 user.js\n
Run Code Online (Sandbox Code Playgroud)\n手动设置rootDir
为src
生成此输出目录:
dist\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 services\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 auth.js\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 user.js\n
Run Code Online (Sandbox Code Playgroud)\n最后,将文件包含rootDir
在include
选项之外会发出错误:
error TS6059: File '~/project/outside.ts' is not under 'rootDir' '~/project/src'. 'rootDir' is expected to contain all source files.\n The file is in the program because:\n Matched by include pattern '**/*' in '~/project/tsconfig.json'\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
9435 次 |
最近记录: |