【问题标题】:Enable tsconfig.json to compileOnSave for .js files启用 tsconfig.json 为 .js 文件 compileOnSave
【发布时间】:2018-05-27 20:03:20
【问题描述】:

我正在使用 Visual Studio Professional 2015 Update 3 和 TypeScript 2.8.4。我有一个简单的项目

Scripts/
└── Widgets/
    ├── main.ts
    └── tsconfig.json

main.ts:

console.log("Hello, world!");

tsconfig.json

{
    "compileOnSave": true,
    "compilerOptions": {
        "allowJs": true,
        "noImplicitAny": false,
        "noEmitOnError": true,
        "removeComments": false,
        "sourceMap": true,
        "target": "es5",
        "outFile": "dist/widgets.js"
    },
    "exclude": [
        "dist"
    ]
}

compileOnSave 设置就像这样工作得很好。但是,当我将main.ts 更改为main.js 时,它不会在保存时编译,尽管设置了allowJs 设置。我可以做些什么让compileOnSave 为扩展名为.js 的文件工作?

【问题讨论】:

  • 你希望它在保存 main.js 时编译什么?
  • @paul,我希望它编译的内容与我使用 Visual Studio 手动构建项目时相同,即 console.log 语句和源映射注释。
  • Sourcemaps 将 typescript 映射到已编译的 javascript。在你的例子中,我认为,没有什么要编译的(没有打字稿)所以不需要源图
  • @paul,你可能误解了我的问题?编译器似乎工作正常。 compileOnSave 不适用于 .js 文件。

标签: javascript visual-studio typescript tsconfig


【解决方案1】:

这在 Visual Studio 2015 中是不可能的。它应该在 Visual Studio 2017 中工作。

https://github.com/Microsoft/TypeScript/issues/14536

【讨论】:

    猜你喜欢
    • 2019-03-27
    • 2015-07-09
    • 2021-11-28
    • 2016-08-23
    • 1970-01-01
    • 2022-01-03
    • 2016-06-02
    • 2022-11-11
    • 2017-07-04
    相关资源
    最近更新 更多