【问题标题】:compile typescript with a visual studio code task, specifying the output directory使用 Visual Studio 代码任务编译打字稿,指定输出目录
【发布时间】:2016-07-05 22:57:50
【问题描述】:

我在编译我的打字稿文件的 Visual Studio 代码中有这个任务。我想通过将所有打字稿添加到一个文件夹并将所有 javascript 添加到另一个文件夹来制作更清晰的文件结构。我如何更改我的任务的参数来做到这一点?我当前的代码导致它将输出编译为与打字稿位于同一文件夹中。这是当前代码:

{
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur.
    "showOutput": "silent",

    // args is the HelloWorld program to compile.
    "args": [
        "scripts/front_end/view_models/search_filter_view_model.ts",
        "scripts/front_end/models/area_getter.ts",
         "scripts/front_end/bootstrap_app.ts",
         "scripts/front_end/models/category.ts",
         "scripts/front_end/plugins/slideshow.ts"
    ],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}

【问题讨论】:

    标签: javascript typescript visual-studio-code


    【解决方案1】:

    我不确定您的项目中发生了什么。但这是我在用于我的角度项目的 tsconfig.json 中使用的内容。您可能希望将其用作项目的示例并进行相应修改。 outDir 和 outFile 我猜是你需要的。

    {
      "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": true,
        "noImplicitAny": false,
        "outDir":"client/build/",
        "outFile": "client/build/all.js",
        "declaration": true
      },
      "exclude": [
        "node_modules",
        "server"
      ],
      "include": [
            "client/*.ts",
            "client/**/*.ts",
            "client/**/**/*.ts"
      ]   
    }
    
    // Include all folders to put to a file.
    /*    "outDir":"client/build/",
        "outFile": "client/build/all.js" */
    

    【讨论】:

    • 谢谢。 outDir是js文件所在的目录吗?来自 ts 文件的所有 js 是否都放入一个文件(client/build/all.js)?所以你的js都在client/build/all.js?
    • outDir 是所有 js 文件的构建所在的目录。outFile 几乎相同,但不同之处在于它包含捆绑(所有 js 文件)文件名。它包含从 include 部分中提到的 ts 文件转换而来的所有 js 文件。 tsconfig.json 文件路径相对于提到的文件夹路径。所以在编译时检查一下。
    猜你喜欢
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多