vscode试调ts

一、新建工程如下
在这里插入图片描述
二、安装依赖

npm install ts-node --save-d
npm install typescript --save-d

三、.vscode 配置文件

  1. launch.json配置
{
   // 使用 IntelliSense 了解相关属性。 
   // 悬停以查看现有属性的描述。
   // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
   "version": "0.2.0",
   "configurations": [
       {
           "type": "node",
           "request": "launch",
           "name": "启动程序",
           "skipFiles": [
               "<node_internals>/**"
           ],
           "program": "${workspaceFolder}\\dist\\demo.js",  //指向 ts 编译后的目录文件
           "outFiles": [
               "${workspaceFolder}/**/*.js"
           ]
       }
   ]
}
  1. tasks.json 自动编译输出 tsc --init 命令生成配置文件
{
   // See https://go.microsoft.com/fwlink/?LinkId=733558
   // for thedocumentation about the tasks.json format
  "version": "2.0.0",
  "shell": true,
  //-p 指定目录;-w watch,检测文件改变自动编译
  "presentation": {
      "reveal":"always"
  },
  "problemMatcher": "$tsc",
  "tasks": [{
   "label": "Run debugger ts",
   "type": "shell",
   "args": ["-p", ".", "-w"],
   "command": "tsc",
   "group": "build", 
  }]
}

四、生成编译文件

  1. ctrl + shift + p
    在这里插入图片描述
  2. ctrl + shift + b
    在这里插入图片描述
    在这里插入图片描述
    五、启动debugger
    在这里插入图片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章