使用webstorm 调试 typescript
安装依赖:
- 安装
npm install typescript ts-node -D
- 注意这两个依赖必须安装在本地,安装在全局不行
配置Configurations templates
- 选择 右上角 add configuration
- 选择templates下的node.js
- 在Node parameters 中添加
--require ts-node/register
- 在Working directory 中指定项目根目录作为作用空间
- 在JavaScript Files中指定要调试的宏命名:
$FilePathRelativeToProjectRoot$
- Applicaiton parameters,可以指定运行参数。如
--project tsconfig.json
,此时你可以指定使用项目根目录中的ts配置。
配置Configurations 运行/调试ts的命令
- 选择左上角的 +
- 然后选择Configurations 下templates中的Node.js
- 更改name为
run ts