码迷,mamicode.com
首页 > Web开发 > 详细

使用vscode 搭建 typescript 的nodejs 自动编译自动启动服务

时间:2018-01-27 19:11:46      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:div   exe   添加   name   config   star   int   lis   post   

1、在项目中安装nodemon 模块

npm install nodemon --save -dev

  

2、在package.json中添加以下脚本

(注意配置文件里的 src 路径问题 )

{  
  "name": "server",  
  "version": "0.0.0",  
  "scripts": {  
    "postinstall": "tsc -p .",  
    "watch": "tsc -w -p .",  
    "debug": "nodemon --watch ./src --inspect=0.0.0.0:5858 --nolazy ./src/*.js",  
    "docker-debug": "docker-compose up",  
    "start": "node ./src/*.js"  
  },  
  "devDependencies": {  
    "@types/node": "^6.0.50",  
    "typescript": "^2.3.2",  
    "nodemon": "^1.11.0"  
  },  
  "main": "*.js"  
}  

   

3、生成.vscode 文件夹下的 launch.json 和 tasks.json 文件

其中launch.json 如下:

{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "nodemon",
            "protocol": "auto",
            "preLaunchTask": "tsc-watch",
            "runtimeExecutable": "npm",
            "env": {
                "NODE_ENV": "dev"
            },
            "restart": false,
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "outFiles": [
                "${workspaceFolder}/src/js/test.js"
            ]
        }
    ]
}

  

 

tasks.json 如下:

{  
    "version": "0.1.0",  
    "tasks": [  
        {  
            "taskName": "tsc-watch",  
            "command": "npm",  
            "isShellCommand": true,  
            "args": [  
                "run",  
                "watch"  
            ],  
            "isBackground": true,  
            "isBuildCommand": true,  
            "problemMatcher": "$tsc-watch",  
            "showOutput": "always"  
        }  
    ]  
}  

 

按键F5 或者 点击菜单 任务-运行任务 点击tsc-watch 即可!

 

使用vscode 搭建 typescript 的nodejs 自动编译自动启动服务

标签:div   exe   添加   name   config   star   int   lis   post   

原文地址:https://www.cnblogs.com/yanliangnh/p/8366655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!