假设我有一个项目,它的主要源目录是:
C:\product\src
基于此目录,每个导入路径都与其相关。即,假设:
// Current script: C:\product\src\com\name\product\blah.ts
import { thing } from '/com/name/product/thing';
如同:
// Current script: C:\product\src\com\name\product\blah.ts
import { thing } from '../../../com/name/product/thing';
我的条目编译文件将位于:
C:\product\src
例如。那么,有没有办法在编译器选项中指定这种入口路径(C:\product\src
例如)?我需要在tsconfig.json
文件中指定这个,因为我将使用 webpack。
我已经尝试了上面的示例,但是 TypeScript 说找不到请求的模块:
// Current script: A.ts
import { B } from '/com/B';
// Current script: B.ts
export const B = 0;
我的 tsconfig.json 文件(在另一个项目中,但都相似):
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"preserveConstEnums": true,
"removeComments": true,
"sourceMap": true,
"strictNullChecks": true,
"target": "ES6"
},
"include": [
"./src/**/*.ts",
"./src/**/*.d.ts"
]
}