【问题标题】:Compiling TypeScript to JavaScript using Visual Studio Code使用 Visual Studio Code 将 TypeScript 编译为 JavaScript
【发布时间】:2017-08-02 07:07:51
【问题描述】:

我是 NodeJS 和 TypeScript 的新手,我想从设置我的项目文件夹开始。我已经有了我的 tsconfig.json

{
"compilerOptions": {
    "outDir": "./build",
    "module": "commonjs",
    "target": "es5",
    "noImplicitAny" : false
},
"files": [
    "./src/**/*.ts"
],
"exclude": [
    "node_modules"
]}

和 package.json

    {
      "name": "crm",
      "version": "1.0.0",
      "description": "",
      "main": "app.js",
      "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC"
    }

这是我的简单目录结构:

    crm/
     |-src/
       |- main/
          |- app.ts

当我使用 tsc 命令编译时,我预计编译后的目录会是

    crm/
     |-build/
       |- main/
          |- app.js

     |- src/
        |- main/
           |- app.ts

但结果是

    crm
     |- build/
        |- app.js

     |- src/
        |- main/
           |- app.ts

没有创建主文件夹。

我不知道问题出在 tsconfig.json 还是 tsc 命令上

【问题讨论】:

  • 你想在build中维护文件夹结构还是在原地编译并放入src
  • 我希望它是构建文件夹中的输出目录
  • 好的..添加了答案..试试吧

标签: node.js typescript visual-studio-code


【解决方案1】:

你已经设置了

"outDir": "./build",

在您的 tsconfig.json 中,没有 rootDir。 检查编译器选项here

设置所需的输出构建路径。

"outDir": "./build",
"rootDir": "./src"

你会得到

crm
 |- build/
    |- main/
       |- app.js

源:this issue

【讨论】:

    猜你喜欢
    • 2020-12-22
    • 2018-04-14
    • 2018-03-12
    • 2016-09-12
    • 2017-04-13
    • 2021-06-20
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多