typescript项目搭建

1.初始化node及typescript

npm init -y && npm install -g typescript && npm install @types/typescript --save-dev && npm install @types/node --save-dev && tsc --init

2.创建目录和文件

./src
./dist
src/index.js

3.修改tsconfig.json

"target": "ES2017"
"lib": ["ES2017"]
"sourceMap": true
"outDir": "./dist"
"rootDir": "./src"
"strict": true
"moduleResolution": "node"
"baseUrl": "./"

4.修改package.json

"main": "./dist/index.js"
"scripts":{
	"dev": "rm -rf ./dist && tsc && node dist/index.js"
}

5.修改 .vscode/launch.json

"program": "${workspaceFolder}/dist/index.js"
"preLaunchTask": "build"

6.修改 .vscode/tasks.json

"label": "build"
"type": "npm"
"script": "dev"

你可能感兴趣的:(typescript项目搭建)