koa ts node调试

1. 安装库

npm install -g ts-node
npm install -g typescript

2. 在package.json里面写

"scripts": {
      "start": "ts-node src/index.ts",

详细package.json如下:

   "devDependencies": {
      "@types/koa": "^2.0.48",
      "tslint": "^5.16.0",
      "@types/node": "^8.0.29"
   },
   "dependencies": {
      "@types/koa-bodyparser": "^4.2.2",
      "@types/koa-static": "^4.0.1",
      "@types/koa-websocket": "^5.0.3",
      "axios": "^0.19.0",
      "date-fns": "^1.30.1",
      "koa": "^2.7.0",
      "koa-bodyparser": "^4.2.1",
      "koa-static": "^5.0.0",
      "koa-websocket": "^5.0.1",
      "koa2-cors": "^2.0.6",
      "mysql": "^2.14.1",
      "reflect-metadata": "^0.1.10",
      "ts-node": "^3.3.0",
      "typeorm": "0.2.17",
      "typescript": "^2.4.2"
   },
   "scripts": {
      "start": "ts-node src/index.ts",
      "build": "npm run tslint && npm run build-ts",
      "build-ts": "tsc",
      "watch": "npm run tslint && npm run watch-ts",
      "watch-ts": "tsc -w",
      "tslint": "tslint -c tslint.json -p tsconfig.json"
   }

3. 新加tsconfig.json文件,内容如下

{
    "compilerOptions": {
       "lib": [ "dom", "es5", "es6", "es2015.promise" ],
       "target": "es2015",
       "module": "commonjs",
       "noImplicitAny": true,
       "allowJs": true,
       "moduleResolution": "node",
       "rootDir": "./src",
       "outDir": "./dist",
       "emitDecoratorMetadata": true,
       "experimentalDecorators": true,
       "skipLibCheck": true,
       "sourceMap": true
    },
    "include": [
       "src/**/*"
    ],
    "exclude": [
       "node_modules",
       "library",
       "local",
       "temp",
       "build",
       "settings"
    ]
 }

4. 搞定,运行

npm start

标签: ts

添加新评论