typescript - 不需要的 *.js 和 *.js.map 文件正在项目的某些区域从 .ts 生成

标签 typescript visual-studio-2017 angular-cli angular-cli-v6

我正在 visual studio 2017 中开发一个 angular cli v6 项目,并注意到正在为我的 typescript 一些生成不需要的 .js 和 .js.map`文件同一个文件夹中的文件。 (我不想要任何生成)

我注意到以角度元素(“服务”、“解析器”、“组件”、“指令”)命名的文件夹内的任何文件似乎都不会创建这些额外的文件。

例如,如果我在 components 文件夹中创建 my-component.component.ts,则不会生成额外的 js/js.map 文件。

我的问题有两个:

  1. 确定是否生成这些额外文件的标准是什么?
  2. 如何防止生成它们

项目文件结构(显示不需要的文件)

 src
 |-- app
 |   |-- components (no generated js/js.map files here)
 |   |   |-- my-component.component.ts
 |   | 
 |   |-- resolvers  (no generated js/js.map files here)
 |   |   |-- my-resolver.resolver.ts
 |   |
 |   |-- services   (no generated js/js.map files here) 
 |   |   |-- my-service.service.ts
 |   |
 |   |-- types      (has generated js/js.map files)
 |   |   |-- my-type.type.js  **dont want this file!**
 |   |   |-- my-type.type.js.map **dont want this file!**
 |   |   |-- my-type.type.ts

这是我的 tsconfig.json 文件

ClientApp/tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

ClientApp/src/tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

ClientApp/src/tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts",
    "polyfills.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

ClientApp/e2e/tsconfig.e2e.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/e2e",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "jasminewd2",
      "node"
    ]
  }
}

最佳答案

这将是由于某些进程使用与您在问题中提供的配置不同的配置调用 tsc 命令造成的。

如果这是 angular-cli,我会感到惊讶,所以我怀疑是 visual studio 本身。

在您的 visual studio 项目设置中,查看 typescript 选项并尝试在保存时禁用编译/类似

此外,值得检查您的项目目录中是否有任何其他 tsconfig 文件,以防其他配置导致不正确的行为。

当然,您需要手动删除这两个文件,看看它们在进行任何更改后是否会恢复。

关于typescript - 不需要的 *.js 和 *.js.map 文件正在项目的某些区域从 .ts 生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51994568/

相关文章:

angular - 使用 ionic 3 angular 4 导航页面到选项卡页面推送

c# - MVC 路由 .net 核心

angular - 如何在 Angular cli 中为应用程序提供服务包括 http 和 https

angular-cli - 即使我使用的是目标 esm2015,ivy 也会编译为 esm5 模块

在 aot 编译构建后 Angular 2 路由不起作用

javascript - 为什么 typescript 类中的这种结构在编译正常时会导致运行时错误?

javascript - 如何在 .vue 文件的 <script> 部分的父组件中处理通过 this.$emit 发出的自定义子事件?

windows - Visual Studio 2017 不启动,但产生一个进程

c# - 从 Visual Studio 2017 发布 API 应用程序后收到错误消息 "An error occurred while starting the application."

angular 2 typescript 无法在环境上下文中声明实现