typescript环境搭建及ts文件调试方法
warning:
这篇文章距离上次修改已过433天,其中的内容可能已经有所变动。
在TypeScript中设置环境并进行代码调试,通常需要以下步骤:
- 安装Node.js和npm。
使用npm安装TypeScript编译器:
npm install -g typescript初始化一个新的npm项目(如果你的项目还没有):
npm init -y安装TypeScript本地依赖:
npm install --save-dev typescript创建一个tsconfig.json文件,该文件定义了TypeScript编译选项:
tsc --init- 编写你的TypeScript文件,比如
index.ts。 使用tsc编译器编译TypeScript文件:
tsc或者使用tsc的监听模式,它会在你保存文件时自动编译:
tsc --watch安装Node.js的调试器:
npm install --save-dev node-inspector启动node-inspector服务:
node-inspector启动Node.js的调试模式,并连接到node-inspector:
node --inspect-brk ./node_modules/.bin/ts-node index.ts或者如果你已经编译了JavaScript文件:
node --inspect-brk index.js
现在你可以在浏览器中打开 http://127.0.0.1:8080/(node-inspector的默认Web界面)并开始调试。
评论已关闭