【问题标题】:Intellij Idea - compiling Typescript to Javascript and keeping directory structureIntellij Idea - 将 Typescript 编译为 Javascript 并保持目录结构
【发布时间】:2016-08-12 21:11:26
【问题描述】:

我试图让 Intellij Idea 在将 Typescript 编译为 Javascript 时保留目录结构。我的目录结构如下:

root
- ts
  - SomeClass1.ts
  - SomeFolder
    - AwesomeClass2.ts
- tsc

我希望生成的编译文件是:

root
- tsc
  - SomeClass1.js
  - SomeFolder
    - AwesomeClass2.js

这是我的 Typescript 配置:

但是在尝试编译时,我在控制台中收到此错误:

  • 如果我将“使用输出路径”设置为“tsc”,它可以工作,但目录结构消失了,导致 RequireJS 不再找到文件。
  • 如果我将“使用输出路径”设置为“tsc\$FileDirRelativeToSourcepath$”,我会得到“无法读取未定义的'replace'属性”。
  • 如果我禁用“使用输出路径”并将“--outDir”与“命令行选项”一起使用,文件会编译到正确的目录中,但如果文件已更改,IntelliJ 将不再自动重新编译。李>

更新,Nitzan Tomer 的解决方案:

在根目录下创建tsconfig.json:

{
  "compilerOptions": {
    "module": "amd",
    "target": "es5",
    "outDir": "tsc",
    "rootDir": "ts",
    "sourceMap": true,
    "declaration": true
  },
  "exclude": [
    "tsc"
  ]
}

并在 IntelliJ 中启用“使用 tsconfig.json”。

【问题讨论】:

    标签: javascript intellij-idea typescript


    【解决方案1】:

    如果你使用tsconfig.json,你可以指定rootDiroutDir,如果你这样做了,那么它会在outDir内的编译版本中保留rootDir的目录结构。

    在你的情况下:

    {
        "compilerOptions": {
            "outDir": "tsc",
            "rootDir": "ts",
            "sourceMap": true,
            "declaration": true
        }
    }
    

    将此文件作为tsconfig.json 放在您的root 目录和intellij/webstorm Enable Typescript Compiler 然后Use tsconfig.json

    【讨论】:

    • 成功了,谢谢!我确实添加了一个排除指令,因为它试图编译“tsc”中的文件。我将使用 tsconfig.json 更新我原来的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    相关资源
    最近更新 更多