安装typescript
- npm init -y 生成packge.json文件
- 安装typescript
-
npm install typescript -
yarn add typescript
- 生成tsconfig.json 文件
-
tsc --init
- 需要tsconfig.json的配置
-
"outDir":"./dist" 编译后生成js文件保存的目录 -
"rootDir":"./src" 编写源码所在的目录 -
dist,src,tsconfig.json,packge.josn 必须在同一个目录下
- 编译src目录以及子目录的ts文件
-
tsc 在src当前目录下运行一下
- 安装ts-node
-
ts-node让node能直接执行ts代码,无需编译成js -
npm install ts-node -
yarn add ts-node
- 安装nodemon 自动检测工具
-
yarn add nodemon -
npm install nodemon
8.在packge.json中配置自动检测,自动重启应用程序
-
"scripts":{ "dev":"nodemon --watch src/ -e ts --exec ts-node ./src/app/ts" }
parcel打包支持浏览器运行的ts文件
- 安装parcel
-
npm install parcel-bundler --save-dev -
yarn add parcel-bundler
2.在packge.json中添加启动项
-
"scripts":{ "start":"parcel ./index.html" }
- 启动parcel工具包
-
yarn start -
npm run start
添加jest单元测试
- npm i jest ts-jest @types/jest -D
- package.json下 "scripts": { "test": "jest"}