TypeScript编译器:生成的源,根目录,排除和符号链接

释放双眼,带上耳机,听听看~!

我有一个TypeScript 2.0.3项目的设置:


1
2
3
4
5
1src/main/webapp/tsconfig.json
2src/main/webapp/app -- contains .ts files
3src/main/webapp/app/tsModels -- a symlink to ../../../../target/tsModels
4target/tsModels/   -- contains .ts files
5

目标是在目标/ tsModels中编译.ts文件.

首先,使用“rootDir”:“.”,tsc抱怨:

error TS6059: File ‘[…]/target/tsModels/AboutWindupModel.ts’ is not under ‘rootDir’ ‘[…]/src/main/webapp’. ‘rootDir’ is expected to contain all source files.

所以我试过了


1
2
3
4
5
6
7
1{
2  "compilerOptions": {  ...,
3    //"rootDir": ".",
4    "rootDirs": [".", "../../../target/tsModels"],
5  },
6}
7

还是一样.尝试:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1{
2  "compilerOptions": {
3    //"rootDir": ".",
4    "rootDirs": [".", "../../../target/tsModels"],
5  },
6  "exclude": [
7    "node_modules",
8    "target/**",
9    "../../../target/**",
10    "../../../target/**/*",
11    "../../../target/tsModels/*",
12    "typings/main",
13    "typings/main.d.ts"
14  ]
15}
16

但仍然得到那个错误.

所以似乎tsc无法正确处理符号链接,总是检查规范路径.

所以我想,好吧让我们直接编译tsModels文件.所以我删除了符号链接并尝试:


1
2
3
4
5
1"compilerOptions": {
2    //"rootDir": ".",
3    "rootDirs": [".", "../../../target/tsModels"],
4  },
5

但这实际上并没有编译tsModels目录中的文件.
我甚至试过了


1
2
1"rootDirs": "../../../target/tsModels",
2

但是tsc没有编译那个,相反,它编译了..它完全服从了吗?

如何从两个目录编译文件?
有没有办法在rootDir之外使用导致dir的符号链接?

完整配置我正在尝试的所有垃圾:

    {
“compilerOptions”:{
“目标”:“es5”,
“模块”:“系统”,
“moduleResolution”:“节点”,
“sourceMap”:是的,
“emitDecoratorMetadata”:是的,
“experimentalDecorators”:是的,
“removeComments”:false,
“noImplicitAny”:false,
//“rootDir”:“.”,
//“rootDirs”:[“.”,“../../../target /tsModels”],
“rootDirs”:[“../../../target/tsModels”],
//“rootDir”:“../../../target /tsModels”,
“outDir”:“../../../target/windup-web”,
“sourceRoot”:“/ windup-web /”
},
“排除”:[
“node_modules”
//“目标/**”,
//“../../../目标/**”,
//“../../../目标/**/*”,
//\”../../../target/tsModels/*”
// “目标/ tsModels / **”,
“分型/主”,
“分型/ main.d.ts”
]
}

我认为preserveSymlinks编译器选项可以帮助您:

Do not resolve symlinks to their real path; treat a symlinked file like a real one.

https://www.typescriptlang.org/docs/handbook/compiler-options.html

例:


1
2
3
4
5
6
1{
2    "compilerOptions": {
3        "preserveSymlinks": true
4    }
5}
6

给TA打赏
共{{data.count}}人
人已打赏
安全经验

图解教程:Google Adsense和百度联…

2021-10-11 16:36:11

安全经验

安全咨询服务

2022-1-12 14:11:49

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索