【问题标题】:What makes it possible to debug typescript in chrome?是什么使得在 chrome 中调试 typescript 成为可能?
【发布时间】:2018-01-28 18:47:26
【问题描述】:

当浏览器只能理解 Javascript 时,是什么使得在 chrome 中调试 typescript 成为可能?我总是在使用 chrome 开发人员工具的 angular CLI 创建的 angular 项目中调试我的 typescript 文件,但是我不知道我们如何能够调试 typescript 文件的原因。谁能给我解释一下?

【问题讨论】:

标签: angular google-chrome typescript


【解决方案1】:

Angular CLI 使用 webpack。当 webpack 将你的 TS 转换为 JS 时,它可以被配置(并且默认情况下)来生成源映射。这就是 Chrome 能够将 javascript 代码绑定回 typescript 以进行调试的方式。

Angular CLI 生成的示例 tsconfig.json

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-03
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    相关资源
    最近更新 更多