【问题标题】:Typescript compiler (tsc) and relative pathTypescript 编译器 (tsc) 和相对路径
【发布时间】:2018-12-26 06:44:39
【问题描述】:

我想编译文件及其依赖项。我的目标是使用相对路径导入依赖项。

/root/subfolder/myFile.ts 中的示例:

import { myFunction } from '~/functions' 

波浪号~ 应该表明myFunction 来自根文件夹

root
|-- functions.ts
`-- subfolder
    `-- myFile.ts

【问题讨论】:

    标签: typescript webpack tsc


    【解决方案1】:

    您可以在tsconfig.json 中将以下内容添加到compilerOptions

    "baseUrl": "src", // must be the same as "rootDir"
    "paths": {
      "~/*": ["./*"]
    }
    

    【讨论】:

      猜你喜欢
      • 2020-03-29
      • 1970-01-01
      • 2011-12-16
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 2017-09-15
      相关资源
      最近更新 更多